One common mistake is to shadow "err" variables without intending to.
For instance, if I write:
inx, err := getIndex()
if err != nil {
return
}
and my function has an err return variable, I am actually not checking the correct err variable above because the locally scoped variable "err" shadows the return variable. To remedy this, I want to use "e" instead of "err" whenever possible and return e explictly:
func example() (err error) {
inx, e := getIndex()
if e != nil {
return e
}
}
One common mistake is to shadow "err" variables without intending to.
For instance, if I write:
and my function has an err return variable, I am actually not checking the correct err variable above because the locally scoped variable "err" shadows the return variable. To remedy this, I want to use "e" instead of "err" whenever possible and return e explictly: