encoding/json: include property name for marshal errors #25153
Labels
Milestone
Comments
I took this opportunity to dig into the go stdlib and I wanted this to be among my first contributions to the project. I have changes ready in a git branch that I can open a PR with, and I am definitely open to feedback on this proposal ahead of that step. |
@dominicbarnes feel free to submit a patch, either on Gerrit or on GitHub. Even if the suggestion ends up being rejected, there's no harm in posting it. |
Change https://golang.org/cl/110119 mentions this issue: |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
Yes
What operating system and processor architecture are you using (
go env
)?What did you do?
When encountering an error using
json.Marshal()
(and related functions) the error returned gives no indication where the error was encountered. The only included metadata is about the type of the value that was being encoded, but that is usually insufficient to narrow down problems without the original input value. (which may not always be at hand)What is being proposed?
The proposal would be to add the property name for marshal errors (using dot notation to signify hierarchy). For example:
would be updated to be more specific:
and in the case of a more complex/nested data structure:
Why is this useful?
I use Go to do a lot of data processing, which is generally from 3rd-parties (aka: customers) so the structure of data is not usually known ahead of time, not to mention weird values being sent due to programming errors and a host of other problems.
Last week, I encountered the first error message above and needed to do some extra work just to determine which property was causing the error, when the encoder should be able to communicate that to the caller.
The text was updated successfully, but these errors were encountered: