multierr

package
v0.6.4 Latest Latest
Warning

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

Go to latest
Published: Mar 3, 2023 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Error

type Error []error

func Append

func Append(err1, err2 error) Error

Append adds err2 to err1. - If err1 and err2 are nil, returns nil - If err1 is nil, returns an Error with only err2 - If err2 is nil, returns an Error with only err1 - If err1 is an Error, it returns a copy with err2 appended - Otherwise, returns a new Error with err1 and err2 as the sole elements NOTE: unlike `err1.Append`, this does not mutate err1.

func (*Error) Append

func (e *Error) Append(err error)

Append will mutate e and append the error. Will no-op if `err == nil`. Typical usage should be via auto-referencing [syntax sugar](https://go.dev/ref/spec#Calls):

var e Error
e.Append(err)

func (Error) As

func (e Error) As(target interface{}) bool

As implements the interface used in errors.As by iterating through the members returning true on the first match.

func (Error) ErrOrNil

func (e Error) ErrOrNil() error

ErrOrNil is used to convert this multierr into a [error]. This is necessary because it is a typed nil

func example() error {
	var e Error
	return e
}
if example() != nil {
	! this will run!
}

in otherwords,

(Error)(nil) != nil

Additionally, if there's only a single error, it will automatically unwrap it.

func (Error) Error

func (e Error) Error() string

func (Error) Is

func (e Error) Is(target error) bool

Is implements the interface used in errors.Is by iterating through the members returning true on the first match.

func (Error) Unwrap

func (e Error) Unwrap() error

Unwrap implements the interface used in errors.Unwrap

Jump to

Keyboard shortcuts

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