-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Opa format panic caused by comments #6330
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
Comments
Thanks for reporting this @sirpi 👍 Sounds like you've done some research already. Would you want to try and fix it? 🙂 Is an error message the expected behavior though? Perhaps I'm missing something obvious, but I'd expect the formatter to format anything as long as it's valid Rego. |
This commit adds a basic check for comment merge conflicts, and provides a helpful error message if a conflict happens during formatting. Fixes open-policy-agent#6330 Signed-off-by: Philip Conrad <[email protected]>
@anderseknert How should the two comments be merged together? Is that a case the formatter can resolve on its own? |
Formatting the rego file without any complaint would be even better :) But I don't see how the comments should be merged automatically. Because a general solution should solve this for any number of comments as well:
just to give an idea. Thanks for asking to fix this, but I am not familiar enough with Go to confidently touch this code. My observation came from simply running format commands with different inputs. And I also see there is a fix with proper error handling and I appreciate it! |
Yes, sorry if I wasn't clear on that — if the formatter can't prettify some lines, I'd expect it to just skip those and proceed to format the rest of the file. The formatter should never bail out on valid Rego. |
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. |
Short description
Wrongly placed comments can cause a panic error message in cli.
OPA version: any (tested even with 0.57.0)
Type: CLI
Steps To Reproduce
opa fmt mypolicy.rego
Shortest rego content:
For that, the following stack trace appears:
Expected behavior
A comprehensive error message without a stack trace would be more suitable.
The root cause of this is the clever mechanism which moves comments to the end of a formatted line if that would appear in the middle. Though if there is already a comment there, we get this error.
Additional context
The text was updated successfully, but these errors were encountered: