specificErr seems more reasonable.
@storozhukBM I guess both are fair style choices. I wanted to pick one, so that all my code would be consistent. specificError
seemed more natural to me: if the first word is long and written in full, might as well write "Error" in full too.
@shurcooL I always use specific names for errors, so compiler can help me to detect not checked ones, as not used variables.
That's an interesting approach. I haven't seen that before. Thanks for sharing.
I know there are tools such as errcheck
and staticcheck
that can help detect unchecked errors even if you reuse the same err
variable.
IMO, use const
for exported sentinel errors is much better.
type sentinel string
func (s sentinel) Error() string {
return string(s)
}
const (
ErrorSomething sentinel = "something wrong"
)
Do this:
Don't do this:
For consistency. See https://go.dev/talks/2014/names.slide#14.