Report invalid --format-options as a CLI error, not a traceback - #1945
Open
seven7763 wants to merge 1 commit into
Open
Report invalid --format-options as a CLI error, not a traceback#1945seven7763 wants to merge 1 commit into
seven7763 wants to merge 1 commit into
Conversation
An invalid --format-options value (bad type, unknown key, bare section) escaped parse_format_options() as an unhandled argparse.ArgumentTypeError and crashed with a traceback. Catch it in _process_format_options() and route it through self.error() so it is reported like every other CLI error. Fixes httpie#1938
Author
|
Heads-up on CI: the failures here (encoding/charset tests + coverage) are repo-wide — PR #1944 shows the same 37 failing checks with unrelated changes. Locally |
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.
Summary
Fixes #1938.
An invalid
--format-optionsvalue crashed with an unhandledargparse.ArgumentTypeErrortraceback:_process_format_options()callsparse_format_options()manually after parsing, so theArgumentTypeErrorraised for bad input is never converted into a normal CLI error. This catches it there and routes it throughself.error(), which is the same pattern the parser already uses for other invalid-flag combinations.Changes
httpie/cli/argparser.py: wrap theparse_format_options()loop in_process_format_options()withtry/except argparse.ArgumentTypeError→self.error(str(ex))tests/test_output.py: 3 regression tests (bad type / unknown key / bare section), asserting a cleanerror:message,ExitStatus.ERROR, and no tracebackValidation
mainbefore the fix (all traceback)python -m pytest tests/test_output.py -q— 123 passed; the one failure (TestQuietFlag::test_double_quiet_on_error) also fails on unmodifiedmainin this environment and is untouched by this changeNotes
No message wording changed — the same messages from
parse_format_options()are surfaced, just without the traceback.