Skip to content

Fix: log_error respects --quiet flag when stdout is redirected - #1992

Open
vinayK34 wants to merge 1 commit into
httpie:masterfrom
vinayK34:fix/quiet-flag-redirected-stdout
Open

vinayK34 wants to merge 1 commit into
httpie:masterfrom
vinayK34:fix/quiet-flag-redirected-stdout

Conversation

@vinayK34

Copy link
Copy Markdown

Fixes #1978

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 bypassed the quiet threshold check entirely.

This meant that even with the --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.

… 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.
@vinayK34
vinayK34 marked this pull request as ready for review October 29, 2026 11:08

@rahul05ranjan rahul05ranjan left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.json prints http: warning: HTTP 404 File not found to 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 with LOG_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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: log_error ignores --quiet flag when stdout is redirected

2 participants