-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Potential issue with opa fmt when interacted via stdin #2235
Comments
I think this is normal, you either have to have a newline+ctrl-d or use two ctrl-d's to indicate that the input is done. If you do just a single ctrl-d in bash (not sure if its just bash, or linux, etc) just sends the line without an EOF. So you need either the newline or the second ctrl-d to get the EOF through. You get the same behavior with other unix-y tools (try it out with |
But I'm having a "newline + Ctrl-D" in the first example and it reproduces the bug. |
Sorry! I totally misread the issue from the first example. That is not normal 😄 |
Looks like this might be intentional behavior if there are no changes after formatting: Lines 161 to 164 in 29d8fbb
Will need to look into why it does that, and if we are OK with changing that behavior. In the short term with the plugin if you can just check if it has nothing in stdout from |
Checked with the team and we're ok to make the behavior change to always write the formatted policy to stdout. |
There was an explicit check that would prevent writing to stdout if the formatting didn't change anything. This makes sense for the "write to file" or "diff" options as we can save work by bailing out early, but if configured to write the file contents to stdout we should do so in all cases. Fixes: open-policy-agent#2235 Signed-off-by: Patrick East <[email protected]>
Thanks @patrick-east for the quick update. :-) I'm happy that this is getting fixed! |
There was an explicit check that would prevent writing to stdout if the formatting didn't change anything. This makes sense for the "write to file" or "diff" options as we can save work by bailing out early, but if configured to write the file contents to stdout we should do so in all cases. Fixes: #2235 Signed-off-by: Patrick East <[email protected]>
Expected Behavior
Should properly format and write out the code
Actual Behavior
Produces no output. (This has a side effect of deleting the entire code when this is integrated with editors!)
Steps to Reproduce the Problem
This is a sample step to reproduce:
Note that if
Ctrl-D
is pressed without entering a newline, it works as expected:Additional Info
This is much frequently reproduced when automatic formatting is enabled on the emacs major mode for rego: https://github.com/psibi/rego-mode
The text was updated successfully, but these errors were encountered: