Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better JSON type mismatch errors #1147

Merged
merged 9 commits into from
Dec 18, 2024
Merged

Conversation

RyanUnderhill
Copy link
Member

@RyanUnderhill RyanUnderhill commented Dec 14, 2024

This changes the JSON parsing to use a std::variant so there just a single OnValue handler vs OnString/OnNumber/OnBool/OnNull.

Previously a mismatched type would say

JSON Error: Unknown value: name at line 3 index 19

or it would say

JSON Error: Unknown value: name

if the name was known but the type of its value was wrong (example: #1146).

Now it'll give a much better error message, showing first the full path of the field being parsed, and then saying exactly how the types mismatch:

JSON Error: model:type - Expected a number but saw a string at line 3 index 19

…e handlers, and gives us much better error messages for mismatched types.
@RyanUnderhill RyanUnderhill merged commit c77e525 into main Dec 18, 2024
13 of 14 checks passed
@RyanUnderhill RyanUnderhill deleted the ryanunderhill/json_variant branch December 18, 2024 03:59
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.

3 participants