Skip to content

Commit

Permalink
compiler: fix error message on missing with target (#4458)
Browse files Browse the repository at this point in the history
"with keyword target must start with input or data"
=>
"with keyword target must reference existing input or data"

Fixes #4431

Signed-off-by: Anders Eknert <anders@eknert.com>
  • Loading branch information
anderseknert committed Mar 22, 2022
1 parent 821e638 commit 8387989
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion ast/compile.go
Expand Up @@ -4615,7 +4615,7 @@ func rewriteWithModifier(c *Compiler, f *equalityFactory, expr *Expr) ([]*Expr,

func validateTarget(c *Compiler, term *Term) *Error {
if !isInputRef(term) && !isDataRef(term) {
return NewError(TypeErr, term.Location, "with keyword target must start with %v or %v", InputRootDocument, DefaultRootDocument)
return NewError(TypeErr, term.Location, "with keyword target must reference existing %v or %v", InputRootDocument, DefaultRootDocument)
}

if isDataRef(term) {
Expand Down
4 changes: 2 additions & 2 deletions ast/compile_test.go
Expand Up @@ -3710,7 +3710,7 @@ func TestCompilerRewriteWithValue(t *testing.T) {
{
note: "invalid target",
input: `p { true with foo.q as 1 }`,
wantErr: fmt.Errorf("rego_type_error: with keyword target must start with input or data"),
wantErr: fmt.Errorf("rego_type_error: with keyword target must reference existing input or data"),
},
}

Expand Down Expand Up @@ -5786,7 +5786,7 @@ func TestQueryCompiler(t *testing.T) {
q: "x = 1 with foo.p as null",
pkg: "",
imports: nil,
expected: fmt.Errorf("1 error occurred: 1:12: rego_type_error: with keyword target must start with input or data"),
expected: fmt.Errorf("1 error occurred: 1:12: rego_type_error: with keyword target must reference existing input or data"),
},
{
note: "rewrite with value",
Expand Down

0 comments on commit 8387989

Please sign in to comment.