Skip to content

fix: map missing_required_field to MissingRequiredFieldsError#237

Merged
felipefreitag merged 1 commit into
resend:mainfrom
mayankbohradev:fix/missing-required-field-error-name
Jul 15, 2026
Merged

fix: map missing_required_field to MissingRequiredFieldsError#237
felipefreitag merged 1 commit into
resend:mainfrom
mayankbohradev:fix/missing-required-field-error-name

Conversation

@mayankbohradev

@mayankbohradev mayankbohradev commented Jul 11, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Register the documented API error name missing_required_field (singular) so it raises MissingRequiredFieldsError.
  • Keep missing_required_fields (plural) as a backward-compatible alias.
  • Add unit tests for both names.

Why

Resend error docs define missing_required_field (singular). The Python SDK ERRORS map only had missing_required_fields (plural), so a real 422 with name: "missing_required_field" fell through to generic ResendError. Callers catching MissingRequiredFieldsError never matched.

Validation (before / after)

Reproducible with the public mapper (no network):

from resend.exceptions import (
    MissingRequiredFieldsError,
    ResendError,
    raise_for_code_and_type,
)

# Before this change:
#   missing_required_field  -> ResendError
#   missing_required_fields -> MissingRequiredFieldsError
#
# After this change:
#   both names -> MissingRequiredFieldsError

for name in ("missing_required_field", "missing_required_fields"):
    try:
        raise_for_code_and_type(422, name, "Missing `to` field")
    except MissingRequiredFieldsError:
        print(name, "-> MissingRequiredFieldsError")
    except ResendError as e:
        print(name, "->", type(e).__name__)

Expected after this PR:

missing_required_field -> MissingRequiredFieldsError
missing_required_fields -> MissingRequiredFieldsError

Same path as Request.perform / AsyncRequest.perform, which pass data["name"] into raise_for_code_and_type.

Testing

  • pytest tests/exceptions_test.py (16 passed)
  • mypy resend/exceptions.py tests/exceptions_test.py
  • flake8 --max-line-length=130 ./resend/exceptions.py

Summary by cubic

Correctly raises MissingRequiredFieldsError for 422 responses with the documented missing_required_field name, so callers catching this exception now match real API errors.

  • Bug Fixes
    • Map missing_required_field in the 422 ERRORS table; keep missing_required_fields as a legacy alias.
    • Add unit tests for both names and update the raise_for_code_and_type docstring.

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

Review in cubic

The Resend API and docs emit singular missing_required_field on 422
responses. The SDK only registered the plural key, so callers catching
MissingRequiredFieldsError never matched real API errors.
@codecov-commenter

Copy link
Copy Markdown

Codecov Report

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

Additional details and impacted files
@@             Coverage Diff             @@
##             main     #237       +/-   ##
===========================================
+ Coverage   82.66%   95.96%   +13.29%     
===========================================
  Files           4       61       +57     
  Lines          75     3219     +3144     
===========================================
+ Hits           62     3089     +3027     
- Misses         13      130      +117     

☔ 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.

@github-actions github-actions Bot added the linear-synced PR has been synced to Linear label Jul 13, 2026
@drish drish self-requested a review July 14, 2026 18:01
@felipefreitag

Copy link
Copy Markdown
Member

Thank you @mayankbohradev !

@felipefreitag felipefreitag merged commit daee53e into resend:main Jul 15, 2026
10 checks passed
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