errors

package
v0.8.0 Latest Latest
Warning

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

Go to latest
Published: Aug 6, 2017 License: MIT Imports: 2 Imported by: 0

Documentation

Overview

Package errors extends the errors package in the stdlib.

Index

Constants

This section is empty.

Variables

View Source
var ErrMissingValue = errors.New("(MISSING)")

ErrMissingValue is appended to keyvals slices with odd length to substitute the missing value.

Functions

func New added in v0.6.0

func New(text string) error

New returns an error that formats as the given text.

This is an alias to the stdlib errors.New function.

func Recover

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.6.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 WithPrefix added in v0.6.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 ContextualError added in v0.6.0

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

ContextualError represents an error which holds a context.

type ErrorCollection added in v0.4.0

type ErrorCollection interface {
	Errors() []error
}

ErrorCollection holds a list of errors.

type MultiErrorBuilder added in v0.4.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.4.0

func NewMultiErrorBuilder() *MultiErrorBuilder

NewMultiErrorBuilder returns a new MultiErrorBuilder.

func (*MultiErrorBuilder) Add added in v0.4.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.4.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.4.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.

Jump to

Keyboard shortcuts

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