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

rego_parse_error with unexpected / confusing message and location #4672

Closed
anderseknert opened this issue May 9, 2022 · 2 comments · Fixed by #4773
Closed

rego_parse_error with unexpected / confusing message and location #4672

anderseknert opened this issue May 9, 2022 · 2 comments · Fixed by #4773
Assignees
Labels

Comments

@anderseknert
Copy link
Member

If you can spot the error in the below function — good eyes! In fact, even the Rego parser fails to identify the location here, which is the call to time.diff and the incorrect parens used on the next last line.

within_time_slot(slot) {
    slot_split := split(slot, ":")
	
    slot_hour := to_number(slot_split[0])
    slot_minute := to_number(slot_split[1])
    
    now_rfc3339 := time.parse_rfc3339_ns(to_rfc_3339(datetime[0], datetime[1], datetime[2], datetime[3], datetime[4]))
    slot_rfc3339 := time.parse_rfc3339_ns(to_rfc_3339(datetime[0], datetime[1], datetime[2], slot_hour, slot_minute))
    
    # The date has already been determined - check only diff in hours and minutes
    [_, _, _, diff_hours, diff_minutes, _] := time.diff(now_rfc3339), slot_rfc3339))
    
    diff_hours * 60 + diff_minutes < 90
}

The error message reported from this however is:

1 error occurred: policy.rego:32: rego_parse_error: unexpected assign token: non-terminated set
	    slot_split := split(slot, ":")
	               ^

Full playground example here: https://play.openpolicyagent.org/p/IeLICFb2TD

@philipaconrad
Copy link
Contributor

I'd be interested in working on this issue and a few others like it once I clear out more of my work backlog. Better error reporting is always useful!

@philipaconrad philipaconrad self-assigned this May 25, 2022
@philipaconrad
Copy link
Contributor

philipaconrad commented May 25, 2022

I'm adding a close-to-minimal test case to this thread that exercises the same confusing behavior:

package test

p {
    x := 5
    y := contains("a"), "b")
}

Error message:

1 error occurred: policy.rego:4: rego_parse_error: unexpected assign token: non-terminated set
	    x := 5
	      ^

EDIT: This case can actually be reduced further:

p {
    y := contains("a"), "b")
}

philipaconrad added a commit to philipaconrad/opa that referenced this issue Jun 14, 2022
This parser change allows the parser to properly fall through to the RHS
case where it was not doing so before, due to returning early during MHS
parsing in the parseTermIn() function.

Fixes open-policy-agent#4672.

Signed-off-by: Philip Conrad <philipaconrad@gmail.com>
srenatus pushed a commit that referenced this issue Jun 14, 2022
This parser change allows the parser to properly fall through to the RHS
case where it was not doing so before, due to returning early during MHS
parsing in the parseTermIn() function.

Fixes #4672.

Signed-off-by: Philip Conrad <philipaconrad@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants