ugorji / go

idiomatic codec and rpc lib for msgpack, cbor, json, etc. msgpack.org[Go]
MIT License
1.86k stars 295 forks source link

`io.ErrUnexpectedEOF` should be returned instead of `io.EOF` when only partial data is present #398

Closed extemporalgenome closed 12 months ago

extemporalgenome commented 1 year ago

codec returns io.EOF upon receiving truncated/incomplete data:

https://go.dev/play/p/retXRYuAszH

The documentation for io.EOF specifically indicates it should be used for graceful end-of-stream operations, and that io.ErrUnexpectedEOF should be used when more data was expected.

As such, I'd hope/expect the above playground link to print "unexpected EOF" rather than just "EOF".

This would allow me to distinguish between, for example, streamed reads where there is literally no more data available (we hit EOF before reading any bytes), versus a case where we read some bytes, but could not successfully parse the value.