Proposal Details
The EOF error is a common error that is reported in IO operations and is often exactly the right error at a finer granularity. However, when composed as part of a larger grammar or file format, many EOF errors should actually be converted into ErrUnexpectedEOF. However, it is often forgotten, leading to bugs where parsing a truncated file or input silently fails. In fact, there have been several bugs of this nature even within the Go standard library:
...and certainly many bugs outside of the standard library (hence the motivation for this helper).
I propose the addition of the following helper function:
func NoEOF(err error) error {
if err == EOF {
return ErrUnexpectedEOF
}
return err
}
This won't inherently prevent bugs of this nature, but at least provides a helper making it easier to provide the appropriate fix. In our own code, we have the equivalent function declared in multiple places.
This proposal does not use errors.Is based on the result of #39155.
Proposal Details
The
EOFerror is a common error that is reported in IO operations and is often exactly the right error at a finer granularity. However, when composed as part of a larger grammar or file format, many EOF errors should actually be converted intoErrUnexpectedEOF. However, it is often forgotten, leading to bugs where parsing a truncated file or input silently fails. In fact, there have been several bugs of this nature even within the Go standard library:...and certainly many bugs outside of the standard library (hence the motivation for this helper).
I propose the addition of the following helper function:
This won't inherently prevent bugs of this nature, but at least provides a helper making it easier to provide the appropriate fix. In our own code, we have the equivalent function declared in multiple places.
This proposal does not use
errors.Isbased on the result of #39155.