Skip to main content

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

This error is raised when the Rego parser encounters an unexpected { token. Like many language, Rego used { and } to denote blocks of code. This error is raised when the parser encounters a { token where it was not expecting one, or where it was unable to find the matching } token.

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

Examples

A simple example of a policy that contains this error follows, note the extra { after input.roles == {}:

package policy

import rego.v1

deny if {
input.roles == {}{
input.user != "admin"
}

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

1 error occurred: policy.rego:6: rego_parse_error: unexpected { token: expected \n or ; or }
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 unmatched {} characters. Many text editors will highlight matching brackets to help you find the issue.

Community

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