errors

package module
v1.2.1 Latest Latest
Warning

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

Go to latest
Published: Feb 16, 2023 License: MIT Imports: 7 Imported by: 3

README

go-errror

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Append

func Append(left error, right error) error

Append appends the given errors together. Either value may be nil.

This function is a specialization of Combine for the common case where there are only two errors.

err = multierr.Append(reader.Close(), writer.Close())

The following pattern may also be used to record failure of deferred operations without losing information about the original error.

func doSomething(..) (err error) {
	f := acquireResource()
	defer func() {
		err = multierr.Append(err, f.Close())
	}()

func As

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

func Combine

func Combine(errors ...error) error

func Errors

func Errors(err error) []error

func Is

func Is(err, target error) bool

Types

type Error

type Error struct {
	Inner    error
	Code     int
	Message  string
	Layer    string
	Category string
	Payload  MapData
}

func New

func New(msg string) *Error

func Newc added in v1.1.0

func Newc(code int, msg string) *Error

func Newcf added in v1.1.0

func Newcf(code int, format string, a ...interface{}) *Error

func Newf added in v1.1.0

func Newf(format string, a ...interface{}) *Error

func (*Error) Error

func (err *Error) Error() string

func (*Error) Unwrap

func (err *Error) Unwrap() error

func (*Error) With added in v1.1.0

func (err *Error) With(options ...Option) *Error

type MapData added in v1.1.0

type MapData = map[string]interface{}

type MultiError

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

MultiError is an error that holds one or more errors.

An instance of this is guaranteed to be non-empty and flattened. That is, none of the errors inside MultiError are other MultiErrors.

MultiError formats to a semi-colon delimited list of error messages with %v and with a more readable multi-line format with %+v.

func (*MultiError) As

func (merr *MultiError) As(target interface{}) bool

func (*MultiError) Error

func (merr *MultiError) Error() string

func (*MultiError) Errors

func (merr *MultiError) Errors() []error

Errors returns the list of underlying errors.

This slice MUST NOT be modified.

func (*MultiError) Format

func (merr *MultiError) Format(f fmt.State, c rune)

func (*MultiError) Is

func (merr *MultiError) Is(target error) bool

type Option

type Option func(err *Error)

func Category added in v1.1.0

func Category(category string) Option

func Inner added in v1.1.0

func Inner(inner error) Option

func Layer added in v1.1.0

func Layer(layer string) Option

func Payload added in v1.2.0

func Payload(payload MapData) Option

Jump to

Keyboard shortcuts

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