opentofu: Add a flag to treat warnings as errors
OpenTofu Version
1.6.0-alpha2
Use Cases
In a number of environments (like mine), deprecation warnings are to be fixed before commit.
Attempted Solutions
Only those ones that involve adding complex grep regexes and shell scripting.
Proposal
Add a flag like -warnings-are-errors or -pedantic to let the tool fail with non-zero return value also in case of warnings.
Default behavior would not treat warnings as error, thus retaining backward compatibility.
References
No response
About this issue
- Original URL
- State: open
- Created 3 years ago
- Reactions: 4
- Comments: 31 (19 by maintainers)
I believe the second option, “change the output colour to red (in the case of a colourised message) and write the warning to stderr as well as return the non-zero return code?”
Given that the flag would be needed in multiple places, I would prefer a global flag. It can be a no-op if it’s not useful for the given command. @opentofu/core-engineers what do you think?
I think we should implement this as originally described and create a followup issue to track include/exclude of warnings in pedantic mode.
(The following is just my personal opinion and not an official decision from the OpenTofu Core team. Please don’t immediately prepare or update any pull requests based on these ideas.)
When I consider the tradeoff above (about how to present the “promoted” warnings), the main concern that comes to my mind is this:
The person who is receiving the messages may not be the person who added the extra option to the command line in the automation environment, and they may not be someone who is already highly experienced with OpenTofu and thus able to infer from memory which of the messages are “real” errors and which of them are just warnings pretending to be errors. While sometimes that distinction won’t matter, I do tend to want to prioritize having a reader of a message understand its cause and action as well as possible before consulting any other materials.
With that tradeoff in mind, I would propose the following compromise:
commandpackage,backendpackage, etc), add an additional Error diagnostic “just in time” which is explicit that warnings are being treated as errors and mentions why that is so.An example of the potential additional message:
This gives the reader direct feedback about what has happened any why it has happened, so they can decide how to proceed. Leaving the original warning messages still marked as warnings makes it clearer which of the diagnostic messages this additional error relates to, in case there are also some truly-error messages in the set for which removing
-pedanticwould not have any effect.In particular, I suspect that with the initial form of this feature (without any mechanism to specify only a subset of warnings to “promote”) there will be situations where it’s impossible to proceed without temporarily disabling this option to allow the correction of something that’s causing a warning. Some warnings are caused directly or indirectly by something that’s present in the prior state rather than in the configuration or on the command line, in which case successfully performing a plan and apply round (or some other workflow phase) would likely be the only way to clear the warning.
Making it clear that this is something a team chose to impose on themselves and that they can choose to (temporarily or permanently) un-impose it to solve a problem feels important to me, so that a person in that situation doesn’t waste too much time stuck in that state before they get a hint on how to escape from it.
@ucfchandra I have a pull request that is waiting to be reviewed thanks.
Yeah so that can be done by mapping codes to warnings and having an additional flag to indicate warnings to ignore such as
--ignore-warnings=WARN100,WARN200etc.@cam72cam can you provide any insight on what you think about this and whether it should be included with this piece of work.
I’d imagine we might need a mechanism here to be able to “ignore” specific warnings. That would allow users to ignore specific unwanted warnings that cannot really be addressed, and prevent the action from failing
We discussed this with the core team,
--pedanticsounds good to us and we’d prefer a global flag.