Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

provide a more useful error message when there are conflicting default rules #7164

Merged

Conversation

tjons
Copy link
Contributor

@tjons tjons commented Nov 10, 2024

Why the changes in this PR are needed?

Resolves #6897.

When there are multiple default rules in a package, the OPA compiler will error out with an unhelpful error message only providing the location of one default rule. This is confusing for users and can be improved by adding all default rule locations to the error message.

What are the changes in this PR?

Provide the location of all default rules in the resultant error when there are more than one default rule in the fileset compiled.

Notes to assist PR review:

Further comments:

Copy link

netlify bot commented Nov 10, 2024

Deploy Preview for openpolicyagent ready!

Name Link
🔨 Latest commit f22a71c
🔍 Latest deploy log https://app.netlify.com/sites/openpolicyagent/deploys/672ffc8374896d0008787799
😎 Deploy Preview https://deploy-preview-7164--openpolicyagent.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@tjons tjons force-pushed the tjons/6897-regotypeerror-ux branch 3 times, most recently from 58a45ec to f22a71c Compare November 10, 2024 00:21
Copy link
Contributor

@srenatus srenatus left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great quality of life improvement 👏 Thank you for your contribution.

@@ -2068,7 +2068,7 @@ func TestCompilerCheckRuleConflictsDotsInRuleHeads(t *testing.T) {
`package pkg.p
default q.w.r = 4
q.w.r = 2`),
err: "rego_type_error: multiple default rules data.pkg.p.q.w.r found",
err: "rego_type_error: multiple default rules data.pkg.p.q.w.r found at mod0.rego:2, mod1.rego:2",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm a little surprised that the ordering here is stable across test re-runs without sorting the defaultRules slice. But if that's the case, fine; we can fix it if it ever becomes a problem later.

@ashutosh-narkar ashutosh-narkar merged commit c47b8c1 into open-policy-agent:main Nov 12, 2024
28 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

"rego_type_error: multiple default rules" should include all locations where found
3 participants