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

Improve reporting of rego_unsafe_var_error #6393

Open
anderseknert opened this issue Nov 8, 2023 · 1 comment
Open

Improve reporting of rego_unsafe_var_error #6393

anderseknert opened this issue Nov 8, 2023 · 1 comment

Comments

@anderseknert
Copy link
Member

The way we currently report rego_unsafe_var_errors is really confusing, and reasonably more so for people new to Rego. Given a policy like this:

package play

rule {
    my_string := x
    
    startswith(my_string, "foo")
    
    substr := substring(my_string, 0, 1)
    
    substr == "f"
}

Rego Playground

There's really one unsafe reference here, which is that to x. The way we report this however is cascading — i.e. all references following the first failure are included as well:

3 errors occurred:
policy.rego:4: rego_unsafe_var_error: var my_string is unsafe
policy.rego:4: rego_unsafe_var_error: var x is unsafe
policy.rego:8: rego_unsafe_var_error: var substr is unsafe

That my_string and substr are unsafe is simply a consequence of x being so, and reporting that does not help with debugging — it rather makes it harder. We who have worked with Rego for a long time have just come to mentally filter these errors, but there's no reason we should. For anyone else, this likely contributes to a bad debugging experience.

(That the list of errors reported isn't ordered — and changes randomly at re-evaluation does nothing to help with this, but that's an issue that would fix itself by not reporting multiple unsafe vars in the first place.)

@ashutosh-narkar
Copy link
Member

Agreed from a debugging perspective especially for new users improving this would be helpful.

@ashutosh-narkar ashutosh-narkar added this to Backlog in Open Policy Agent via automation Nov 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Open Policy Agent
  
Backlog
Development

No branches or pull requests

2 participants