jbrukh / ggit

ggit
17 stars 2 forks source link

Make sure all error handling is working. #5

Closed jbrukh closed 11 years ago

jbrukh commented 11 years ago

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
    }
}