open-policy-agent/opa

Back-to-back metadata blocks triggers misleading parse error

Opened this issue · 2 comments

If a policy has two METADATA blocks declared back-to-back, with no empty lines in-between, e.g.:

package play

# METADATA
# title: Ps
# scope: document
# METADATA
# title: P
p := rego.metadata.chain()

A hard to understand, and possibly misleading error is generated:

policy.rego:7: rego_parse_error: yaml: line 4: could not find expected ':'

Presumably, this error is rooted in the second METADATA header being interpreted as a yaml attribute, and is expected to be followed by a :. This is however not very helpful to the author, as they clearly intended to start a new set of annotations, and not to add another annotation to the first block.

Opinion: although it can be argued it's more readable to separate METADATA blocks with newlines, there is no real reason to disallow this in the parser; and should instead be seen as something a linter (like Regal) should have opinions about.

This issue has been automatically marked as inactive because it has not had any activity in the last 30 days. Although currently inactive, the issue could still be considered and actively worked on in the future. More details about the use-case this issue attempts to address, the value provided by completing it or possible solutions to resolve it would help to prioritize the issue.