Skip to content

fix: preserve SDK errors for invalid JSON byte encodings - #276

Open
Bortlesboat wants to merge 3 commits into
resend:mainfrom
Bortlesboat:fix/json-response-decode-errors
Open

fix: preserve SDK errors for invalid JSON byte encodings#276
Bortlesboat wants to merge 3 commits into
resend:mainfrom
Bortlesboat:fix/json-response-decode-errors

Conversation

@Bortlesboat

@Bortlesboat Bortlesboat commented Sep 8, 2026

Copy link
Copy Markdown

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 its Retry-After metadata.

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 across resend/, examples/ and tests/ 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.


Compound Engineering


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.

  • Adds UnicodeDecodeError to the JSON decode except clause in resend/request.py and resend/async_request.py.
  • Adds tests for invalid UTF-8, truncated UTF-16, and malformed JSON at HTTP 200, 429, and 502 through both sync and async adapters.
  • Bumps version to 2.43.1.

Written for commit d9fa06e. Summary will update on new commits.

Review in cubic

Bortlesboat and others added 2 commits September 8, 2026 09:56
Signed-off-by: Gabriel Miranda <gabriel@resend.com>

@gabrielmfern gabrielmfern left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks

@codecov-commenter

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 96.90%. Comparing base (7f1acd0) to head (eba77a8).
⚠️ Report is 226 commits behind head on main.

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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@Bortlesboat

Copy link
Copy Markdown
Author

Fixed the mypy failure in d9fa06e. The new response-decoding test now runs its coroutine with asyncio.run, avoiding the untyped pytest decorator while retaining the async request and status/header assertions. Preserved the intervening version bump. All 646 tests pass, mypy passes across 181 source files, and Flake8 passes.

@github-actions github-actions Bot added the linear-synced PR has been synced to Linear label Sep 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

linear-synced PR has been synced to Linear

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants