github.com/jjeffery/errors (go): Package errors provides simple error handling primitives that work well with structured logging.  This package is inspired by the excellent github.com/pkg/errors package. A significant amount of code and documentation in this package has been adapted from that source.  A key difference between this package and github.com/pkg/errors is that this package has been designed to suit programs that make use of structured logging. Some of the ideas in this package were proposed for package github.com/pkg/errors, but after a reasonable amount of consideration, were ultimately not included in that package. (See https://github.com/pkg/errors/issues/34 for details).  If you are not using structured logging in your application and have no intention of doing so, you will probably be better off using the github.com/pkg/errors package in preference to this one.  The traditional error handling idiom in Go is roughly akin to  which applied recursively up the call stack results in error reports without context or debugging information. The errors package allows programmers to add context to the failure path in their code in a way that does not destroy the original value of the error.  The `errors` package provides three operations which combine to form a simple yet powerful system for enhancing the value of returned errors:  The `New` function is used to create an error. This function is compatible with the Go standard library `errors` package:  The `Wrap` function returns an error that adds a message to the original error. This additional message can be useful for putting the original error in context. For example:  The `With` function accepts a variadic list of alternating key/value pairs, and returns an error context that can be used to create a new error or wrap an existing error.  One useful pattern is to create an error context that is used for an entire function scope:  The errors returned by `New` and `Wrap` provide a `With` method that enables a fluent-style of error handling:  Using errors.Wrap constructs a stack of errors, adding context to the preceding error. Depending on the nature of the error it may be necessary to reverse the operation of errors.Wrap to retrieve the original error for inspection. Any error value which implements this interface can be inspected by errors.Cause.  errors.Cause will recursively retrieve the topmost error which does not implement causer, which is assumed to be the original cause. For example:  Errors created by `errors.Wrap` and `errors.New` implement the following interface:  The Keyvals method returns an array of alternating keys and values. The first key will always be "msg" and its value will be a string containing the message associated with the wrapped error.  Example using go-kit logging (https://github.com/go-kit/kit/tree/master/log):  GOOD ADVICE: Do not use the Keyvals method on an error to retrieve the individual key/value pairs associated with an error for processing by the calling program.
Keywords: error-handling|golang|structured-logging