DEV Community

Discussion on: Simple Idea for Improving Error Handling of Go

Collapse
 
krusenas profile image
Karolis

I guess this would be alright if you don't need to actually handle any errors and functions that you call are unrelated. If your functions return a value (that you are going to use) and an error, you probably can't just log an error and continue as that returned value is likely to be nil.

Consider:


users, err := getUsers()
if err != nil {
    // can't just log an error as the 'users' is going to be used
    return err
}
banned, err := banUsers(users)
if err != nil {
    return err
}
_, err := unbanUSers(banned)

And in a scenario where you don't handle any errors, you can also just append them to a slice of errors and decide what you want to do with them in the end :)

Otherwise, handle errors as the official docs suggest :)