Skip to main content

rego_parse_error: unexpected identifier token: expected \n or ; or }

This error is raised when the Rego parser encounters an unexpected identifier token. This is typically caused misplaced whitespace.

StageCategoryMessage
parsingrego_parse_errorunexpected identifier token: expected \n or ; or }

Examples

A simple example of a policy that contains this error follows, note the missing . between input and roles:

package policy

import rego.v1

allow if {
"admin" in input roles
}

The code above will raise the following error, helpfully showing the location in question:

1 error occurred: policy.rego:6: rego_parse_error: unexpected identifier token: expected \n or ; or }
"admin" in input roles
^

How To Fix It

While the fix for this error depends on other elements on the line of Rego in question, the error message will always point to the location of the error to get you started.

Typically, the fix is to correct misplaced whitespace.

Community

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