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

"unexpected assign token" error is almost always wrong and masks real issues #6563

Closed
anderseknert opened this issue Feb 1, 2024 · 0 comments · Fixed by #6778
Closed

"unexpected assign token" error is almost always wrong and masks real issues #6563

anderseknert opened this issue Feb 1, 2024 · 0 comments · Fixed by #6778

Comments

@anderseknert
Copy link
Member

anderseknert commented Feb 1, 2024

This was reported as a side-effect in #6433 but this is actually the main issue, so I'll close that in favor if this one. We really ought to look into the parse error of "unexpected assign token" as it's:

  • Very frequently reported
  • Wrong
  • Hides actual issues from users, thus making Rego development harder than it should be

This is especially problematic for users new to Rego, which makes this a high priority to fix.

Compare:

package play

s := "a
1 error occurred: policy.rego:3: rego_parse_error: unexpected assign token: expected rule value term (e.g., s := <VALUE> { ... })
	s := "a

vs.

package play

s = "a
3 errors occurred:
policy.rego:3: rego_parse_error: non-terminated string
	s = "a
	    ^
policy.rego:3: rego_parse_error: illegal token
	s = "a
	    ^
policy.rego:3: rego_parse_error: illegal token
	s = "a
	    ^

But essentially any errors reported on the right hand side of the assignment operator (:=) will be reported the same way, while using = instead provides the user with the actual error.

Using := is recommended over = and has been for a long time, which explains why this is such a commonly reported error.

anderseknert added a commit to anderseknert/opa that referenced this issue May 31, 2024
This one has been among my top annoyances, and thanks to @johanfylling,
it was easy to finally track down. Had to update a few tests, but not too
many.

Fixes open-policy-agent#6563

Signed-off-by: Anders Eknert <anders@styra.com>
anderseknert added a commit to anderseknert/opa that referenced this issue May 31, 2024
This one has been among my top annoyances, and thanks to @johanfylling,
it was easy to finally track down. Had to update a few tests, but not too
many.

Fixes open-policy-agent#6563

Signed-off-by: Anders Eknert <anders@styra.com>
anderseknert added a commit that referenced this issue May 31, 2024
…#6778)

This one has been among my top annoyances, and thanks to @johanfylling,
it was easy to finally track down. Had to update a few tests, but not too
many.

Fixes #6563

Signed-off-by: Anders Eknert <anders@styra.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Done
Development

Successfully merging a pull request may close this issue.

1 participant