-
Notifications
You must be signed in to change notification settings - Fork 17.4k
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
encoding/json: Decoder does not keep context for nested UnmarshalJSON errors #18227
Labels
Comments
json.Decoder
does not keep context for nested UnmarshalJSON
errors
Can you try Go 1.8beta1? We're no longer making changes to Go 1.7. |
In Go 1.8beta1 :
|
Yes, the Unmarshal of null behavior was changed in 1.8. See https://beta.golang.org/doc/go1.8#encoding_json |
I'm going to close this bug, but if you have a concrete JSON change proposal, please file a proposal per https://github.com/golang/proposal#readme |
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
What version of Go are you using (
go version
)?What operating system and processor architecture are you using (
go env
)?playground : go1.7 amd64p32 - nacl
What did you do?
I triggered a json error :
the error is raised by a specific UnmarshalJSON() function on one of the fields of the go struct value
In this specific example : a time.Time field tries to parse the string "null"
https://play.golang.org/p/SH1R641VzV
What did you expect to see?
some error wrapped into a
json.SomeErrorType
value.maybe a new
json.UnmarshalValueError
:json.UnmarshalValueError{Offset: 24, Fieldname: "Clock", Suberror: time.ParseError{ ... } ...
(some way to get the context of where the error occurred)
What did you see instead?
the raw error value from the time package :
&time.ParseError{Layout:"\"2006-01-02T15:04:05Z07:00\"", Value:"null", LayoutElem:"\"", ValueElem:"null", Message:""}
additional notes
Since using this as the default behaviour would break the backward compatibility promise, maybe add a switch on the
json.Decoder()
type :This would not fix the direct use of
json.Unmarshal()
function, but would still give a way to get this error context.The text was updated successfully, but these errors were encountered: