emperror

package module
v0.7.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 25, 2018 License: MIT Imports: 3 Imported by: 89

README

Emperror

Build Status Go Report Card GoDoc

The Emperor takes care of all errors personally.

Development

The project requires Glide to install dependencies.

$ make dep

When all coding and testing is done, please run the test suite:

$ make check

License

The MIT License (MIT). Please see License File for more information.

Documentation

Overview

Package emperror provides error handling solutions and tools to libraries and applications.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func HandleIfErr added in v0.1.1

func HandleIfErr(handler Handler, err error)

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 With added in v0.5.0

func With(err error, keyvals ...interface{}) error

With returns a new error with keyvals context appended to it. If the wrapped error is already a contextual error created by With or WithPrefix keyvals is appended to the existing context, but a new error is returned.

func WithHttpRequest added in v0.6.0

func WithHttpRequest(err error, r *http.Request) error

WithHttpRequest attaches an HTTP request to the error.

func WithPrefix added in v0.5.0

func WithPrefix(err error, keyvals ...interface{}) error

WithPrefix returns a new error with keyvals context appended to it. If the wrapped error is already a contextual error created by With or WithPrefix keyvals is prepended to the existing context, but a new error is returned.

Types

type Causer added in v0.5.0

type Causer interface {
	Cause() error
}

Causer is the interface defined in github.com/pkg/errors for specifying a parent error.

type Contextor added in v0.5.0

type Contextor interface {
	Context() []interface{}
}

Contextor represents an error which holds a context.

type ErrorCollection added in v0.5.0

type ErrorCollection interface {
	Errors() []error
}

ErrorCollection holds a list of errors.

type Handler

type Handler interface {
	// Handle processes an error.
	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

func HandlerWith(handler Handler, keyvals ...interface{}) Handler

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

func HandlerWithPrefix(handler Handler, keyvals ...interface{}) Handler

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

func NewCompositeHandler(handlers ...Handler) Handler

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 HttpError added in v0.6.0

type HttpError interface {
	HttpRequest() *http.Request
}

HttpError interface provides a way to attach an http.Request to the error.

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 StackTracer added in v0.5.0

type StackTracer interface {
	StackTrace() errors.StackTrace
}

StackTracer is the interface defined in github.com/pkg/errors for exposing stack trace from an error.

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.

func (*TestHandler) Last

func (h *TestHandler) Last() error

Last returns the last handled error.

Directories

Path Synopsis
Package airbrake provides Airbrake integration.
Package airbrake provides Airbrake integration.
Package bugsnag provides Bugsnag integration.
Package bugsnag provides Bugsnag integration.
mocks
Code generated by mockery v1.0.0
Code generated by mockery v1.0.0

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL