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

Incorrect error message when keywords are used on the LHS of comprehensions #6714

Open
charlesdaniels opened this issue Apr 24, 2024 · 0 comments
Labels

Comments

@charlesdaniels
Copy link
Contributor

Short description

In some circumstances, use of keywords on the left hand side of comprehensions can cause the error message to be unexpected identifier token: non-terminated object rather than unexpected ___ keyword. Although OPA is correct to throw an error in this situation, it makes the problem much harder to debug.

Steps To Reproduce

$ opa eval -f pretty '{{"b": bt, "a": as} | as := [1,2,3][_]; bt := ["a","b","c"][_]}'
1 error occurred: 1:8: rego_parse_error: unexpected identifier token: non-terminated object
	{{"b": bt, "a": as} | as := [1,2,3][_]; bt := ["a","b","c"][_]}
	      ^
$ opa eval -f pretty '[{"b": bt, "a": as} | as := [1,2,3][_]; bt := ["a","b","c"][_]]'
1 error occurred: 1:8: rego_parse_error: unexpected identifier token: non-terminated object
	[{"b": bt, "a": as} | as := [1,2,3][_]; bt := ["a","b","c"][_]]
	      ^
$ opa eval -f pretty '{{"a": as, "b": bt} | as := [1,2,3][_]; bt := ["a","b","c"][_]}'
1 error occurred: 1:8: rego_parse_error: unexpected as keyword
	{{"a": as, "b": bt} | as := [1,2,3][_]; bt := ["a","b","c"][_]}
	      ^
$ opa eval -f pretty '[{"a": as, "b": bt} | as := [1,2,3][_]; bt := ["a","b","c"][_]]'
1 error occurred: 1:8: rego_parse_error: unexpected as keyword
	[{"a": as, "b": bt} | as := [1,2,3][_]; bt := ["a","b","c"][_]]

Expected behavior

All of the above examples should have emitted rego_parse_error: unexpected as keyword errors, and pointed to the as, not to the bt, which is an allowed variable name.

Additional context

$ uname -a
Linux eos 6.6.10-76060610-generic #202401051437~1709085277~22.04~31d73d8 SMP PREEMPT_DYNAMIC Wed F x86_64 x86_64 x86_64 GNU/Linux
$ cat /etc/lsb-release
DISTRIB_ID=Pop
DISTRIB_RELEASE=22.04
DISTRIB_CODENAME=jammy
DISTRIB_DESCRIPTION="Pop!_OS 22.04 LTS"
$ opa version 
Version: 0.63.0
Build Commit: bb30b153692aa77738b982e29424c8b24a1ad14a
Build Timestamp: 2024-03-28T15:50:15Z
Build Hostname: 
Go Version: go1.22.2
Platform: linux/amd64
WebAssembly: unavailable
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant