Skip to main content

rego_type_error: multiple default rules {name} found

This error is emitted by the type checker during the compilation stage when multiple default definitions are found for one rule. The error message will show the rule e.g. data.example.allow that has multiple definitions, but the line number for the error will only show the first location.

StageCategoryMessage
compilationrego_type_errormultiple default rules <rule> found

Examples

In the example below, the default value for the allow rule is defined twice:

package example

import rego.v1

default allow := false

allow if input.admin

default allow := false

This will result in the following error:

1 error occurred: policy.rego:5: rego_type_error: multiple default rules data.example.allow found

In this example, it's relatively easy to spot the issue, but in larger policies, it can be more challenging to find the duplicate definitions. It's also possible that the default is defined in a different Rego file. For example:

# example1.rego
package example

default allow := false
# example2.rego
package example

default allow := true

We would see an error like this when using the two files:

$ opa eval data.example.allow -d example1.rego -d example2.rego
1 error occurred: example1.rego:3: rego_type_error: multiple default rules data.example.allow found
info

OPA will load files in lexicographical order, so temporarily renaming the file in the error message can be used to search for the other definitions.

How To Fix It

Fixing this error is usually simple: just remove one of the repeated default definitions if they are setting the same default value. If the intention is to set different default values, this is trickier, but perhaps you'd be better served by two different rules.

Community

For questions, discussions and announcements related to OPA, or Styra products, services and open source projects, please join the Styra Community on Slack.