Repository navigation
Conversation
Environment.log_error() gated the quiet threshold check on
stdout_isatty, so when stdout was redirected (e.g. piping output in a
script) every warning and info message bypassed the devnull'd stderr
and was printed to the original stderr even with -q/-qq, contradicting
the documented behavior of --quiet ('Provide twice to suppress
warnings as well.').
Drop the stdout_isatty condition: with the appropriate quiet level,
messages now go through self.stderr (devnull under --quiet) regardless
of whether stdout is a TTY. Single -q still shows warnings, errors are
never hidden (their threshold is infinite), and the not-quiet path is
unchanged.
Also flips test_quiet_quiet_with_check_status_non_zero_pipe, which
pinned the buggy behavior, to assert documented suppression.
Fixes httpie#1978
Author
|
Noticed #1992 addresses the same issue (#1978) with the same one-line root-cause fix (dropping One difference worth flagging: this PR also updates For context on the red CI: the |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
--quietdoes not suppress warnings/info messages when stdout is redirected (piped to a file or another process), contradicting the documented behavior of the flag:Fixes #1978
Reproduction (on unmodified
master)Any warning emitted while stdout is redirected leaks to stderr even with
-qq. Using a local server that returns HTTP 500:Same happens for e.g. an invalid config file (
http: warning: invalid config file ...).Root cause
Environment.log_error()gates the quiet-threshold check onself.stdout_isatty(httpie/context.py):When stdout is not a TTY the condition short-circuits to
_orig_stderr, so the message is printed regardless of the quiet level. Thestdout_isattygate was introduced together with the original--quietimplementation in #1175 / #1283; no test or discussion back then named piping semantics, andtest_quiet_quiet_with_check_status_non_zero_pipeended up pinning the buggy behavior.Fix
Drop
self.stdout_isattyfrom the condition so the quiet level decides alone:-qq+ redirected stdout: warnings/info are suppressed (via the devnull'dself.stderr), same as on a TTY.-q: warnings still shown, on TTY and pipes alike.LOG_LEVEL_DISPLAY_THRESHOLDS[ERROR]is infinite).test_quiet_quiet_with_check_status_non_zero_pipeis flipped to assert the documented suppression (it previously asserted the bug).Verification
master(assert not r.stderrvs actual'http: warning: HTTP 500...') and passes with the fix. The TTY twin (test_quiet_quiet_with_check_status_non_zero) passes before and after (control).> out.jsonredirection: unmodified master printshttp: warning: HTTP 500 Internal Server Erroron stderr with-qq; with the fix stderr is empty; with a single-qthe warning is still printed.