Scalingo / go-utils

Small libraries and helpers concerning errors, logging, nsq
6 stars 2 forks source link

[errors] `Build` should return an `error` #892

Open EtienneM opened 4 months ago

EtienneM commented 4 months ago

The Build method on ValidationErrorsBuilder should return a pure error rather than a *errors.ValidationErrors:

https://github.com/Scalingo/go-utils/blob/8aba6f49942591600b0761fab6397b944f20107d/errors/validation_errors.go#L88

The current situation may lead to a staticcheck offense never returns a nil interface value. The root cause of this issue is explained here (https://go.dev/doc/faq#nil_error):

It's a good idea for functions that return errors always to use the error type in their signature (as we did above) rather than a concrete type such as *MyError, to help guarantee the error is created correctly

Initially discussed here: https://scalingo.slack.com/archives/C01E42AT2G6/p1717062547454579