Skip to content

Report invalid --format-options as a CLI error, not a traceback - #1938

Open
VXNCXNX wants to merge 1 commit into
httpie:masterfrom
VXNCXNX:fix/format-options-error
Open

Report invalid --format-options as a CLI error, not a traceback#1938
VXNCXNX wants to merge 1 commit into
httpie:masterfrom
VXNCXNX:fix/format-options-error

Conversation

@VXNCXNX

@VXNCXNX VXNCXNX commented Aug 17, 2026

Copy link
Copy Markdown

An invalid --format-options value exits with an unhandled argparse.ArgumentTypeError traceback instead of the normal HTTPie error:

$ http --offline --format-options=json.indent:x pie.dev/get
  File "httpie/cli/argtypes.py", line 244, in parse_format_options
argparse.ArgumentTypeError: invalid value 'x' in 'json.indent:x' (expected int got str)

Same for an unknown section (--format-options=json) or key (--format-options=json.nope:1). _process_format_options calls parse_format_options outside argparse's own type machinery, so the error escapes to the top level. It is now caught and routed through self.error, which is what _guess_method and _parse_items already do a few lines above; --traceback still re-raises, matching those two.

After the fix the same command prints error: --format-options: invalid value 'x' ... and exits 1. Three parametrized cases added in tests/test_output.py. Suite is green apart from two pre-existing big5 charset failures in test_encoding.py, identical on an unmodified checkout: 1020 passed, 2 failed.

AI disclosure: written with Claude Code. I ran the CLI before and after and checked the mutation myself.

Invalid --format-options values now produce a regular CLI error instead of an unhandled ArgumentTypeError traceback. The --traceback flag still re-raises for debugging.
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.

1 participant