Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions httpie/cli/argparser.py
Original file line number Diff line number Diff line change
Expand Up @@ -554,8 +554,11 @@ def _process_download_options(self):
def _process_format_options(self):
format_options = self.args.format_options or []
parsed_options = PARSED_DEFAULT_FORMAT_OPTIONS
for options_group in format_options:
parsed_options = parse_format_options(options_group, defaults=parsed_options)
try:
for options_group in format_options:
parsed_options = parse_format_options(options_group, defaults=parsed_options)
except argparse.ArgumentTypeError as ex:
self.error(str(ex))
self.args.format_options = parsed_options

def print_manual(self):
Expand Down
21 changes: 21 additions & 0 deletions tests/test_output.py
Original file line number Diff line number Diff line change
Expand Up @@ -598,6 +598,27 @@ def test_format_options_accumulation(self, args, expected_format_options):
)
assert parsed_args.format_options == expected_format_options

@pytest.mark.parametrize(
'options, expected_error',
[
('json.indent:x', "invalid value 'x' in 'json.indent:x' (expected int got str)"),
('json.nope:1', "invalid key 'json.nope'"),
('json', "invalid option 'json'"),
]
)
def test_invalid_format_options_reported_as_cli_error(
self, options, expected_error
):
r = http(
'--offline',
'--format-options', options,
'example.org',
tolerate_error_exit_status=True,
)
assert r.exit_status == ExitStatus.ERROR
assert expected_error in r.stderr
assert 'Traceback' not in r.stderr


@responses.activate
def test_response_mime_overwrite():
Expand Down
Loading