The Day the Linter Broke My Code
Another Story…
Imagine you were given a task to design errors for your service.
DataEOFError should contain the name of the data file and be considered equal to io.ErrUnexpectedEOF .
should contain the name of the data file and be considered equal to . ProcessingFailedError should contain a processing ID as a string and wrap a failure Reason error.
should contain a processing as a string and wrap a failure error. Two different ProcessingFailedError instances should not be equal.
Ok, fine: easy.
You’ll write
type DataEOFError string func ( d DataEOFError ) Error () string { return "unexpected EOF in file " + strconv . Quote ( string ( d )) } func ( DataEOFError ) Is ( err error ) bool { return err == io . ErrUnexpectedEOF } var _ error = DataEOFError ( "" )
The Is function is more or less the same as the example. The other error is a piece of cake:
... continue reading