-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
Fix: std.json: Writing inf values returns InvalidJSON error #23258
base: master
Are you sure you want to change the base?
Fix: std.json: Writing inf values returns InvalidJSON error #23258
Conversation
It looks like one of the errors in CI is related to this: #22107 . Anyone with more experience working on the std lib have any thoughts? I can cast the comptime floats to regular floats before the checks, but perhaps |
#22107 (comment) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- You'll have to update the error sets of all
stringify
functions, not juststringifyAlloc
- The doc comment bulletpoint
Zig floats -> JSON number or string.
should be updated to mention this behavior error.InvalidJson
does not accurately describe the failure - this is serialization to JSON and the input value is invalid, not the other way around
I believe this should fix #23253. First time contributor here, so please feel free to be as thorough as you'd like with feedback.
Abstract: Writing an infinite float in JSON produces the value
inf
which is not valid JSON. Since we can not convert an infinite value to JSON, introduce a new error type namedInvalidJson
and return that when attempting to write a value that can not be converted to valid JSON.