go: encoding/json: eof error of NewDecoder().Decode() should be same with Unmarshal()
Please answer these questions before submitting your issue. Thanks!
What version of Go are you using (go version
)?
go version go1.10.1 darwin/amd64
Does this issue reproduce with the latest release?
yes
What operating system and processor architecture are you using (go env
)?
GOARCH=“amd64” GOOS=“darwin”
What did you do?
https://play.golang.org/p/gr5cHhrpmbK
What did you expect to see?
shown in previous link
What did you see instead?
shown in previous link
About this issue
- Original URL
- State: open
- Created 6 years ago
- Reactions: 8
- Comments: 17 (13 by maintainers)
Sir I’m using go1.14
var member Member // struct type err := json.NewDecoder(request.Body).Decode(&member); if err != nil{println(err)} // yeah this return eof & I expected value
I support changing it to
io.ErrUnexpectedEOF
for the following reasons:ErrUnexpectedEOF
, I (and my observation of other parser code) has commonly interpreted that error as indicating that is some number of bytes you could be appended to the string to turn in into a valid input.SyntaxError
is distinguishable, it is functionally less so thanErrUnexpectedEOF
, which only requires a comparison instead of a type assertion.Any news on this?
Sure, I can fix the tests. Just needed a confirmation on whether to go ahead or not.
@dsnet - I tried changing it to
io.ErrUnexpectedEOF
and several tests failed -.Whereas, if I do the other way and change to
SyntaxError
, no tests fail. It seems to me that changing toSyntaxError
may actually be less invasive.But your call. Let me know.