encoding/json: returned io.Writer errors can be confusing without wrapping #48899
Labels
NeedsDecision
Feedback is required from experts, contributors, and/or the community before a change can be made.
Milestone
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
I must assume it does (not a bug, just poor design)
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
Of course, in a stripped-down example the error is obvious. And it was even obvious once I had a clue of what to look for. The reason why I'm posting this issue is because the error message was not only unhelpful, but very misleading. It is a result of the json (and gob and perhaps other) packages simply forwarding error messages from other packages without wrapping them for context.
What did you expect to see?
A useful error message, telling me why Encode had failed.
What did you see instead?
The plain error message "invalid argument", which is very misleading and caused some wasted time trying to source.
When you call a method and receive an error message "invalid argument", it is only natural to assume that the error was due to the arguments passed to said method. However, that is not the case here. The error is actually due to the file which was used to create the encoder. In addition, the error message is so short and plain, I had trouble trying to just determine from where it originated (due to poor searchability).
The text was updated successfully, but these errors were encountered: