Skip to content

fix: raise JSONError for malformed API error bodies instead of AssertionError - #462

Closed
Harsh23Kashyap wants to merge 1 commit into
togethercomputer:mainfrom
Harsh23Kashyap:fix/error-response-assertion
Closed

Harsh23Kashyap wants to merge 1 commit into
togethercomputer:mainfrom
Harsh23Kashyap:fix/error-response-assertion

Conversation

@Harsh23Kashyap

Copy link
Copy Markdown

Have you read the Contributing Guidelines? Yes

Issue #460

Describe your changes

handle_error_response validated the error payload with asserts, but the except only caught KeyError/TypeError, so any error body not shaped as {"error": {...}} - a FastAPI-style {"detail": ...} body, a plain string error, or a non-dict JSON body - escaped as a raw AssertionError (or AttributeError under python -O) and the JSONError fallback was dead code. The asserts are replaced with explicit isinstance checks that raise error.JSONError.

Adds tests/unit/test_error_response_handling.py covering the three malformed body shapes plus the valid 429/400 mappings. The new tests fail on unpatched code (AssertionError) and pass with this change; the full unit suite passes (210 passed).

…ionError

handle_error_response validated the error payload with asserts, but the
except clause only caught KeyError/TypeError, so any error body that was
not {"error": {...}} - a FastAPI-style {"detail": ...} body, a plain
string error, or a non-dict JSON body - escaped as a raw AssertionError
instead of the intended error.JSONError. Replace the asserts with
explicit isinstance checks that raise JSONError.
@broly-code-security-scanner

Copy link
Copy Markdown

Broly Security Scan

Warning

Latest baseline snapshot is stale. Broly is running in PR-only fallback mode until the next scheduled baseline refreshes. This does not block the PR.

Note

Clean scan
No vulnerabilities detected in this PR.

Note

Re-scan this PR anytime with /broly scan — useful after /broly undismiss, or to refresh findings without a new push.

Broly — SAST (zai-org/GLM-5.3) · Secrets · SCA · IaC · GH Actions · Base Images · Supply Chain Threats · Exploit Chains · Adversarial Verification

We're continuously improving Broly's accuracy and finding quality — your feedback is valuable. False positives, missed findings, bugs, and feature requests all welcome.

Ask in #security-engineering   Powered by Together AI

@blainekasten

Copy link
Copy Markdown
Contributor

This repo is deprecated and is not taking new patches. Thanks.

The new SDK is hosted at https://github.com/togethercomputer/together-py

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.

2 participants