Skip to content

Instantly share code, notes, and snippets.

@tylerdmace
Last active October 17, 2018 17:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tylerdmace/dee31310d6815dedd93c72c64eb32c97 to your computer and use it in GitHub Desktop.
Save tylerdmace/dee31310d6815dedd93c72c64eb32c97 to your computer and use it in GitHub Desktop.
Error nilification in Go
package main
import (
"errors"
"fmt"
)
func main() {
err := test()
if err != nil {
err = nil // Nilify error
if err != nil { // For critical code, you should nilify this error too
fmt.Println("You done fucked up. -- Stomach after Chipotle")
}
fmt.Println("Everything is hunky dory. -- David Bowie")
}
}
func test() error {
return errors.New("error")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment