Skip to content

Conversation

ns-fboucault
Copy link

@ns-fboucault ns-fboucault commented Oct 8, 2025

Summary

Replaces a bare assert statement in the argument parser with proper error handling to prevent AssertionError from being exposed to users.

Problem

The _guess_method() function had an assertion that could fail in edge cases:

assert not self.args.request_items  # Line 416

When this fails, users see an unhelpful stack trace instead of a clear error message.

Solution

Replace the assertion with user-facing error handling:

if self.args.request_items:
    self.error('unable to parse arguments: received request items without an HTTP method. ...')

Changes

  • httpie/cli/argparser.py: Replace assertion with self.error() call
  • tests/test_cli.py: Add 2 regression tests to TestArgumentParser class

Testing

All tests pass. Backward compatible - no changes to valid command behavior.

Fixes #1614

@ns-fboucault ns-fboucault force-pushed the fix/issue-1614-assertion-error branch from a3d4bf0 to 3203e22 Compare October 8, 2025 15:33
…ment parser

Replace bare `assert` statement in `_guess_method()` with proper error
handling to prevent AssertionError from being exposed to users.

The assertion `assert not self.args.request_items` at line 416 could fail
in edge cases, causing users to see an unhelpful stack trace instead of a
clear error message.

Changes:
- httpie/cli/argparser.py: Replace assertion with self.error() call
- tests/test_cli.py: Add 2 regression tests to TestArgumentParser class

Fixes httpie#1614
@ns-fboucault ns-fboucault force-pushed the fix/issue-1614-assertion-error branch from 3203e22 to 48c169a Compare October 8, 2025 15:40
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.

AssertionError when trying to POST with bearer auth

1 participant