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

Error message is wrong on ref with keyword in rule head assignment #6433

Closed
anderseknert opened this issue Nov 24, 2023 · 3 comments
Closed

Comments

@anderseknert
Copy link
Member

Continuation of #6432

If the same expression is moved to the rule head, the error message is completely untrue:

package p

r := input.default
opa eval -d p.rego -f pretty data.p.r
1 error occurred: p.rego:3: rego_parse_error: unexpected assign token: expected rule value term (e.g., r := <VALUE> { ... })
	r := input.default

Interestingly, using = instead of := results in a better error message, although for some reason repeated in two variations:

opa eval -d p.rego -f pretty data.p.r
2 errors occurred:
p.rego:3: rego_parse_error: unexpected default keyword: expected ident
	r = input.default
	          ^
p.rego:3: rego_parse_error: unexpected default keyword: expected rule value term (e.g., r[<nil>] = <VALUE> { ... })
	r = input.default

Fixing this along with #6432 would help empower users to identify and fix mistakes they've made.

@anderseknert
Copy link
Member Author

The "unexpected assign token" seems to be everywhere when := is used for rule assignment, and replacing it for = often reveals the real error. We really ought to fix this, as the idiomatic option currently leads to a degraded developer experience :/

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
	    ^

(we could probably do without the "illegal token" errors here, but at least the real error is presented)

Copy link

stale bot commented Jan 13, 2024

This issue has been automatically marked as inactive because it has not had any activity in the last 30 days. Although currently inactive, the issue could still be considered and actively worked on in the future. More details about the use-case this issue attempts to address, the value provided by completing it or possible solutions to resolve it would help to prioritize the issue.

@anderseknert
Copy link
Member Author

Closing in favor of #6563

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant