You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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:
LeGEC
changed the title
json.Decoder does not keep context for nested UnmarshalJSON errors
json.Decoder does not keep context for nested UnmarshalJSON errors
Dec 7, 2016
bradfitz
changed the title
json.Decoder does not keep context for nested UnmarshalJSON errors
encoding/json: Decoder does not keep context for nested UnmarshalJSON errors
Dec 7, 2016
json.Unmarshal() will not raise any error when trying to fit a null value into a non pointer time.Time field (question: is this behaviour as expected ?)
json.Unmarshal() will still return a raw &time.ParseError{...} when trying to unmarshal a value with an incorrect time format
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: