opa icon indicating copy to clipboard operation
opa copied to clipboard

Improve rule conflict error

Open johanfylling opened this issue 2 years ago • 0 comments

The following policy:

package play

p := 1

p.q := 2

p.r[s] := 3 { s := "s" }

will generate the error:

1 error occurred: policy.rego:3: rego_type_error: rule data.play.p conflicts with [data.play.p.q data.play.p.r[__local0__]]

This error has two points that can be improved:

  1. the rewritten var __local0__ is output instead of s for rule p.r[s].
  2. no location is given for the conflicting refs data.play.p.q and data.play.p.r[__local0__].

(2) might get very verbose if location data is added, especially if a rule is declared over multiple modules. A multi-line error might be appropriate:

1 error occurred: policy.rego:3: rego_type_error: rule data.play.p conflicts with:
    rule data.play.p.q at policy1.rego:5, policy2.rego:12
    rule data.play.p.r[s] at policy1.rego:7

the above error assumes an additional module that also declares rule play.p.q on line 12.

johanfylling avatar Nov 07 '23 12:11 johanfylling