errors

package module
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Sep 15, 2021 License: AGPL-3.0 Imports: 7 Imported by: 0

README

godocs.io

An error library that allows wrapping of one error with another, extending with further information and preserving all wrapped errors for comparisons.

Where possible this library wraps standard errors library functions.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func As added in v0.2.0

func As(err error, target interface{}) bool

As wraps "errors".As()

func Is

func Is(err, target error) bool

Is wraps "errors".Is()

func Unwrap added in v0.2.0

func Unwrap(err error) error

Unwrap wraps "errors".Unwrap()

Types

type ErrorContext added in v0.3.0

type ErrorContext interface {
	// implement base error interface
	error

	// Is identifies whether the receiver contains / is the target
	Is(error) bool

	// Unwrap reveals the underlying wrapped error (if any!)
	Unwrap() error

	// Value attempts to fetch contextual data for given key from this ErrorContext
	Value(string) (interface{}, bool)

	// Append allows adding contextual data to this ErrorContext
	Append(...KV) ErrorContext

	// Data returns the contextual data structure associated with this ErrorContext
	Data() ErrorData
}

ErrorContext defines a wrappable error with the ability to hold extra contextual information

func New added in v0.2.0

func New(msg string) ErrorContext

New returns a new ErrorContext created from string

func Newf added in v0.3.0

func Newf(s string, a ...interface{}) ErrorContext

Newf returns a new ErrorContext created from format string

func Wrap added in v0.2.0

func Wrap(err error) ErrorContext

Wrap ensures supplied error is an ErrorContext, wrapping if necessary

func WrapMsg added in v0.3.0

func WrapMsg(err error, msg string) ErrorContext

WrapMsg wraps supplied error as inner, returning an ErrorContext with a new outer error made from the supplied message string

func WrapMsgf added in v0.3.0

func WrapMsgf(err error, msg string, a ...interface{}) ErrorContext

WrapMsgf wraps supplied error as inner, returning an ErrorContext with a new outer error made from the supplied message format string

type ErrorData added in v0.3.0

type ErrorData interface {
	// Value will attempt to fetch value for given key in ErrorData
	Value(string) (interface{}, bool)

	// Append adds the supplied key-values to ErrorData, similar keys DO overwrite
	Append(...KV)

	// String returns a string representation of the ErrorData
	String() string
}

ErrorData defines a way to set and access contextual error data. The default implementation of this is thread-safe

func Data added in v0.3.0

func Data(err error) ErrorData

ErrorData attempts fetch ErrorData from supplied error, returns nil otherwise

func NewData added in v0.3.0

func NewData() ErrorData

NewData returns a new ErrorData implementation

type KV added in v0.3.0

type KV struct {
	Key   string
	Value interface{}
}

KV is a structure for setting key-value pairs in ErrorData

type OnceError

type OnceError struct {
	// contains filtered or unexported fields
}

OnceError is an error structure that supports safe multi-threaded usage and setting only once (until reset)

func NewOnce added in v0.2.0

func NewOnce() OnceError

NewOnce returns a new OnceError instance

func (*OnceError) IsSet

func (e *OnceError) IsSet() bool

func (*OnceError) Load

func (e *OnceError) Load() error

func (*OnceError) Reset

func (e *OnceError) Reset()

func (*OnceError) Store

func (e *OnceError) Store(err error)

Jump to

Keyboard shortcuts

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