Skip to main content

rego_parse_error: unexpected assign token

In some cases when an assign token (:=) preceeds some invalid Rego code, the parser will raise this error.

warning

There is an open issue on OPA to address this error message as it is misleading.

StageCategoryMessage
parsingrego_parse_errorunexpected unexpected assign token

Examples

A simple example of a policy that contains this error follows, note the unmatched " after a :=:

package policy

a := "

The code above will raise the following error:

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

The parser error is pointing to the := token, which in this case is not the issue.

How To Fix It

While the fix for this error depends on other elements on the line of Rego, the error message will usually point to you to the line in question. Have a look for invalid code later on that line as it is likely the cause of the error.

info

Until this issue is resolved, you can use a trick to get more helpful error messages. By changing the := to =, the parser will raise a more helpful error message:

package policy

a = "

This new code will raise the following, more helpful, error:

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

Note however that generally this is not a recommended approach, see more detail here in the Regal docs.

Community

For questions, discussions and announcements related to OPA, or Styra products, services and open source projects, please join the Styra Community on Slack.