Repository navigation
Conversation
… redirected The issue was in the log_error method in httpie/context.py where the condition checked both self.stdout_isatty and self.quiet >= threshold. When stdout is redirected (not a TTY), self.stdout_isatty becomes False, which bypasses the quiet threshold check entirely. This meant that even with --quiet flag, warnings would still be printed to stderr when stdout was redirected. The fix removes self.stdout_isatty from the condition so that the logic mirrors apply_warnings_filter and properly respects the quiet flag regardless of whether stdout is a TTY or not.
rahul05ranjan
left a comment
There was a problem hiding this comment.
Verified the fix end-to-end against a local server returning 404, with stdout redirected to a file:
- master (
git+httpie/cli@master):http -qq --check-status GET .../missing > out.jsonprintshttp: warning: HTTP 404 File not foundto stderr (42 bytes) — the #1978 bug reproduced. - this PR head: same command → stderr is empty, exit status still 4. Fix confirmed.
-q(single) still prints the warning with redirected stdout, which is consistent withLOG_LEVEL_DISPLAY_THRESHOLDS(WARNING needs quiet >= 2) — the threshold semantics are preserved.
Dropping stdout_isatty also makes log_error mirror apply_warnings_filter (httpie/context.py:188), which uses the same self.quiet >= LOG_LEVEL_DISPLAY_THRESHOLDS[...] check, so the two warning paths now agree.
One thing that will need updating in this PR: tests/test_output.py currently pins the old behavior. test_quiet_quiet_with_check_status_non_zero_pipe asserts 'http: warning: HTTP 500' in r.stderr with MockEnvironment(stdout_isatty=False) — exactly the redirected-stdout case this PR changes, so that assertion will now fail on CI. Flipping it to assert not r.stderr both fixes the suite and serves as the regression test for #1978 (there's currently no test covering the redirected+quiet combination).
Two small nits:
- The last hunk removes the trailing newline at EOF of
httpie/context.py(\ No newline at end of file) — worth restoring. - The
# FIXED: Removed self.stdout_isatty...comments narrate the diff rather than the code; something like "stderr choice depends only on the --quiet level, not on whether stdout is a TTY" would document the invariant instead.
Fixes #1978
The issue was in the
log_errormethod inhttpie/context.pywhere the condition checked bothself.stdout_isattyandself.quiet >= threshold. When stdout is redirected (not a TTY),self.stdout_isattybecomes False, which bypassed the quiet threshold check entirely.This meant that even with the
--quietflag, warnings would still be printed to stderr when stdout was redirected.The fix removes
self.stdout_isattyfrom the condition so that the logic mirrorsapply_warnings_filterand properly respects the quiet flag regardless of whether stdout is a TTY or not.