Documentation
¶
Overview ¶
Package emperror provides error handling solutions and tools for libraries and applications.
Index ¶
- func Context(err error) []interface{}
- func ExposeStackTrace(err error) error
- func ForEachCause(err error, fn func(err error) bool)
- func HandleIfErr(handler Handler, err error)
- func HandleRecover(handler Handler)
- func Recover(r interface{}) (err error)
- func StackTrace(err error) (errors.StackTrace, bool)
- func With(err error, keyvals ...interface{}) error
- func Wrap(err error, message string) error
- func WrapWith(err error, message string, keyvals ...interface{}) error
- func Wrapf(err error, format string, args ...interface{}) error
- type Handler
- type HandlerFunc
- type HandlerLogFunc
- type MultiErrorBuilder
- type SingleWrapMode
- type TestHandler
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Context ¶ added in v0.8.0
func Context(err error) []interface{}
Context extracts the context key-value pairs from an error (or error chain).
func ExposeStackTrace ¶ added in v0.8.0
ExposeStackTrace exposes the stack trace (if any) in the outer error.
func ForEachCause ¶ added in v0.8.0
ForEachCause loops through an error chain and calls a function for each of them, starting with the topmost one.
The function can return false to break the loop before it ends.
func HandleIfErr ¶ added in v0.1.1
HandleIfErr handles an error whenever it occurs.
func HandleRecover ¶ added in v0.1.1
func HandleRecover(handler Handler)
HandleRecover recovers from a panic and handles the error.
defer emperror.HandleRecover(errorHandler)
func Recover ¶ added in v0.1.1
func Recover(r interface{}) (err error)
Recover accepts a recovered panic (if any) and converts it to an error (if necessary).
func StackTrace ¶ added in v0.8.0
func StackTrace(err error) (errors.StackTrace, bool)
StackTrace returns the stack trace from an error (if any).
func With ¶ added in v0.5.0
With returns a new error with keyvals context appended to it. If the wrapped error is already a contextual error created by With keyvals is appended to the existing context, but a new error is returned.
func Wrap ¶ added in v0.11.0
Wrap returns an error annotating err with a stack trace at the point Wrap is called (if there is none attached to the error yet), and the supplied message. If err is nil, Wrap returns nil.
Types ¶
type Handler ¶
type Handler interface { // Handle takes care of unhandled errors. Handle(err error) }
Handler is responsible for handling an error.
This interface allows libraries to decouple from logging and error handling solutions.
func HandlerWith ¶ added in v0.7.0
HandlerWith returns a new error handler with keyvals context appended to it. If the wrapped error handler is already a contextual error handler created by HandlerWith or HandlerWithPrefix keyvals is appended to the existing context, but a new error handler is returned.
The created handler will prepend it's own context to the handled errors.
func HandlerWithPrefix ¶ added in v0.7.0
HandlerWithPrefix returns a new error handler with keyvals context prepended to it. If the wrapped error handler is already a contextual error handler created by HandlerWith or HandlerWithPrefix keyvals is prepended to the existing context, but a new error handler is returned.
The created handler will prepend it's own context to the handled errors.
func NewCompositeHandler ¶
NewCompositeHandler returns a new compositeHandler.
func NewNopHandler ¶ added in v0.5.0
func NewNopHandler() Handler
NewNopHandler returns an error handler that doesn't do anything.
type HandlerFunc ¶ added in v0.5.0
type HandlerFunc func(err error)
HandlerFunc wraps a function and turns it into an error handler.
func (HandlerFunc) Handle ¶ added in v0.5.0
func (h HandlerFunc) Handle(err error)
Handle calls the underlying log function.
type HandlerLogFunc ¶ added in v0.5.0
type HandlerLogFunc func(args ...interface{})
HandlerLogFunc wraps a log-like function and turns it into an error handler.
func (HandlerLogFunc) Handle ¶ added in v0.5.0
func (h HandlerLogFunc) Handle(err error)
Handle calls the underlying log function.
type MultiErrorBuilder ¶ added in v0.5.0
type MultiErrorBuilder struct { Message string SingleWrapMode SingleWrapMode // contains filtered or unexported fields }
MultiErrorBuilder provides an interface for aggregating errors and exposing them as a single value.
func NewMultiErrorBuilder ¶ added in v0.5.0
func NewMultiErrorBuilder() *MultiErrorBuilder
NewMultiErrorBuilder returns a new MultiErrorBuilder.
func (*MultiErrorBuilder) Add ¶ added in v0.5.0
func (b *MultiErrorBuilder) Add(err error)
Add adds an error to the list.
Calling this method concurrently is not safe.
func (*MultiErrorBuilder) ErrOrNil ¶ added in v0.5.0
func (b *MultiErrorBuilder) ErrOrNil() error
ErrOrNil returns a MultiError the builder aggregates a list of errors, or returns nil if the list of errors is empty.
It is useful to avoid checking if there are any errors added to the list.
type SingleWrapMode ¶ added in v0.5.0
type SingleWrapMode int
SingleWrapMode defines how MultiErrorBuilder behaves when there is only one error in the list.
const ( AlwaysWrap SingleWrapMode = iota // Always return a MultiError. ReturnSingle // Return the single error. )
These constants cause MultiErrorBuilder to behave as described if there is only one error in the list.
type TestHandler ¶
type TestHandler struct {
// contains filtered or unexported fields
}
TestHandler throws every error away.
func (*TestHandler) Errors ¶
func (h *TestHandler) Errors() []error
Errors returns all the handled errors.
func (*TestHandler) Handle ¶
func (h *TestHandler) Handle(err error)
Handle saves the error in a list.
Source Files
¶
Directories
¶
Path | Synopsis |
---|---|
Package airbrake provides Airbrake integration.
|
Package airbrake provides Airbrake integration. |
Package bugsnag provides Bugsnag integration.
|
Package bugsnag provides Bugsnag integration. |
Package errorlogrus logs an error using Logrus.
|
Package errorlogrus logs an error using Logrus. |