Skip to content

Instantly share code, notes, and snippets.

@andrewchambers
Created August 28, 2018 22:49
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 andrewchambers/4354ae7ece73bba7ff0759267e0bd298 to your computer and use it in GitHub Desktop.
Save andrewchambers/4354ae7ece73bba7ff0759267e0bd298 to your computer and use it in GitHub Desktop.
Error values feedback

In my own code, I use my own error package. My observation is that a root cause of an error is special, most values in the error chain are useless except to preserve line information. Users and debuggers usually only care about the first error and the last error in the chain.

A typical formatting of an error is "Unable to ${TOP_ACTION}: ${ROOT_CAUSE}"

A typical usage of my package is:

err := errors.Wrapf(err, "Additional context: %s", s)
...
if errors.RootCause(err) != sql.ErrNoRows {
  Log("an error happend", "trace", errors.Trace(err))
}

One big lack I found is knowing the possible values of RootCause... A Go guru like analysis may help. especially a way to check reality with what the doc comments say.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment