fix: preserve SDK errors for invalid JSON byte encodings - #276
Open
Bortlesboat wants to merge 3 commits into
Open
fix: preserve SDK errors for invalid JSON byte encodings#276Bortlesboat wants to merge 3 commits into
Bortlesboat wants to merge 3 commits into
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #276 +/- ##
===========================================
+ Coverage 82.66% 96.90% +14.24%
===========================================
Files 4 72 +68
Lines 75 4076 +4001
===========================================
+ Hits 62 3950 +3888
- Misses 13 126 +113 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Author
|
Fixed the mypy failure in d9fa06e. The new response-decoding test now runs its coroutine with |
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.
Malformed JSON bytes now raise the usual SDK error with the response status and headers in both sync and async requests. For example, a 429 response containing invalid UTF-8 previously leaked
UnicodeDecodeError, bypassing the SDK error contract and itsRetry-Aftermetadata.Validation: the new encoding cases produced 12 failures before the fix; all 646 tests now pass with
python -m pytest --cov=resend --cov-report=xml --doctest-modules tests. The tests cover invalid UTF-8, truncated UTF-16 and malformed JSON at HTTP 200, 429 and 502 through both transport adapters. Source flake8 passes on Python 3.11, and mypy passes acrossresend/,examples/andtests/on Python 3.12.No service deployment or new monitoring is needed for this SDK error conversion.
Agent-assisted: Codex prepared the patch and ran the local checks listed above.
Summary by cubic
Fixes sync and async request decoding so malformed byte encodings in JSON responses raise the SDK's standard error with response status and headers instead of leaking
UnicodeDecodeError.UnicodeDecodeErrorto the JSON decode except clause inresend/request.pyandresend/async_request.py.Written for commit d9fa06e. Summary will update on new commits.