Skip to content

Improve missing field error messages#747

Open
AllanChain wants to merge 1 commit intoyukinarit:mainfrom
AllanChain:fix/missing-field-msg
Open

Improve missing field error messages#747
AllanChain wants to merge 1 commit intoyukinarit:mainfrom
AllanChain:fix/missing-field-msg

Conversation

@AllanChain
Copy link
Copy Markdown
Contributor

Missing required fields currently surface as a bare SerdeError("'field'"). For example,

import serde


@serde.serde()
class A:
    a: int


print(serde.from_dict(A, {}))

The above code raises the following error before the fix:

serde.compat.SerdeError: 'a'

Here we catch that KeyError at the required-field lookup site, so pyserde raises a contextual SerdeError with the field and class name while leaving defaulted-field fallback behavior unchanged.

After the fix, the message becomes:

serde.compat.SerdeError: missing required field 'a' while deserializing A

The fix was done with the assistance of LLM, and I reviewed and tested it. It looks reasonable, but I'm not certain if the fix is ideal.

Missing required fields currently surface as a bare
`SerdeError("'field'")`.

Here we catch that `KeyError` at the required-field lookup site so
pyserde raises a contextual `SerdeError` with the field and class name,
while leaving defaulted-field fallback behavior unchanged.
@codecov
Copy link
Copy Markdown

codecov Bot commented May 5, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 90.82%. Comparing base (f09d503) to head (0c0490e).
⚠️ Report is 69 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #747      +/-   ##
==========================================
- Coverage   90.83%   90.82%   -0.02%     
==========================================
  Files          13       13              
  Lines        2040     2310     +270     
  Branches      370      451      +81     
==========================================
+ Hits         1853     2098     +245     
- Misses        124      141      +17     
- Partials       63       71       +8     

☔ View full report in Codecov by Sentry.
📢 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.

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.

1 participant