Shell::warn
versus env_logger
warn!
output is confusingly disjoint.
#8423
Labels
C-bug
Category: bug
Problem
There are two different categories of warnings sent either from
Shell::warn
orenv_logger
and it's not clear what the difference is, and controlling either kind is distinct and decoupled.More Detail on the Problem
While trying to automate
cargo
, I want to fail an operation by policy ifcargo
outputs warnings. (This is specifically forcargo publish
.) After not finding any commandline feature akin to--deny-warnings
(treat warnings as errors) and seeing warnings and other output mixed on my terminal, I thought I would look into usingCARGO_LOG
environment variable to limit output to only errors and warnings, then consider any such output an error in my automation. This approach seeks to avoid parsing any Cargo output other than to detect its presence.To my surprise, however, running
CARGO_LOG=warn cargo publish --dry-run
shows that there are two kinds of warnings:env_logger
emitted warnings and the warnings that appear on stdout which I tracked down to theShell::warn
method. These seem completely disjoint, so I cannot rely onCARGO_LOG
at all to help detect the otherShell::warn
-style warnings which is what I care about.I could see an argument that this is not a bug and that those are just two different streams, maybe one is for "normal users" and one is for "developer diagnostics". Never-the-less since I was surprised and assumed both things called "warnings" would be the same thing, I thought it worth a bug ticket.
Steps
cargo
command that producesShell::warn
output while theCARGO_LOG=warn
environment variable is set. In my case I was runningCARGO_LOG=warn cargo publish --dry-run --locked
in a project without a license file.Possible Solution(s)
A few options:
Shell
output to delegate to the logging system, so that all output has a consistent flow from source to destination, then ensure all warnings go through theShell
layer.Shell::warn
and/or error routines to delegate to the logging system, so the logging system contains a merger of the two different categories of warnings and is always a superset of all warnings.Notes
Output of
cargo version
:The text was updated successfully, but these errors were encountered: