Skip to content

Instantly share code, notes, and snippets.

@pdk
Created August 30, 2018 17:21
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 pdk/ea6851f25ce5bf7c17b63dd11e614b3a to your computer and use it in GitHub Desktop.
Save pdk/ea6851f25ce5bf7c17b63dd11e614b3a to your computer and use it in GitHub Desktop.
chaining error checks
func DoSomethingComplicated() error {
makro checkErrAlpha(..., err error) ... {
if err != nil && IsSpecificErrorType(err) {
return fmt.Errorf("specific error happened: %s", err)
}
}
makro checkErrBeta(..., err error) ... {
checkErrAlpha(..., err)
if err != nil {
return fmt.Errorf("some general error happened: %s", err)
}
}
i, j := checkErrBeta(MoreOtherThings())
x, y := checkErrAlpha(SomeOtherCall())
return nil
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment