errors

package
v3.3.53 Latest Latest
Warning

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

Go to latest
Published: Sep 5, 2023 License: Apache-2.0 Imports: 4 Imported by: 7

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Annotate

func Annotate(err error, msg string) error

Annotate adds a new error in the chain that is some extra context about the error

func Annotatef

func Annotatef(err error, msg string, args ...interface{}) error

Annotatef adds a new formatf error in the chain that is some extra context about the error

func Cause

func Cause(err error) error

Cause of the original error at the end of the chain

func DeferLogIfErr

func DeferLogIfErr(errCallback func() error, l Loggable, msg string, args ...interface{})

DeferLogIfErr will log to l a Printf message if the return value of errCallback is not nil. Intended use is during a defer function whos return value you don't really care about.

func Thing() error {
  f, err := os.Open("/tmp/a")
  if err != nil { return Annotate(err, "Cannot open /tmp/a") }
  defer DeferLogIfErr(f.Close, log, "Cannot close file %s", "/tmp/a")
  // Do something with f
}

func Details

func Details(err error) string

Details are an easy to read concat of all the error strings in a chain

func Errorf

func Errorf(msg string, args ...interface{}) error

Errorf is fmt.Errorf. Note returns error rather than *ChainError so that it matches fmt.Errorf signature

func LogIfErr

func LogIfErr(err error, l Loggable, msg string, args ...interface{})

LogIfErr will log to l a Printf message if err is not nil

func Matches

func Matches(err error, f func(error) bool) bool

Matches is used to wrap the Cause() and is similar to something like:

f, err := do_something()
if Matches(err, os.IsTimeout) {
  // It was a timeout error somewhere...
}

func MatchesI

func MatchesI(err error, m Matcher) bool

MatchesI is like Matches but takes the interface, if you need it.

func Message

func Message(err error) string

Message is the error string at the Head of the linked list

func New

func New(msg string) error

New error. Note returns error rather than *ChainError so that it matches errors.New signature

func NewMultiErr

func NewMultiErr(errs []error) error

NewMultiErr will return nil if there are no valid errors in errs, will return the exact, single error if errs only contains a single error, and will otherwise return an instance of MultiError that wraps all the errors at once.

func Next

func Next(err error) error

Next error just below this one, or nil if there is no next error. Note this may be an error created for you if you used annotations. As a user, you probably don't want to use this.

func PanicIfErr

func PanicIfErr(err error, msg string, args ...interface{})

PanicIfErr is useful if writing shell scripts. It will panic with a msg if err != nil

func PanicIfErrWrite

func PanicIfErrWrite(_ int, err error)

PanicIfErrWrite is similar to PanicIfErr, but works well with io results that return integer+err

func Tail

func Tail(err error) error

Tail of the error chain: at the end

func Wrap

func Wrap(head error, next error) error

Wrap a head function giving it the chain defined in next. Note that wrap may sometimes return head directly if next is nil

Types

type ChainError added in v3.3.43

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

ChainError is a linked list of error pointers that point to a parent above and a child below.

func (*ChainError) Cause added in v3.3.43

func (e *ChainError) Cause() error

Cause lets me simulate errgo

func (*ChainError) Error added in v3.3.43

func (e *ChainError) Error() string

Error returns the error string of the tail of the linked list

func (*ChainError) GetInner added in v3.3.43

func (e *ChainError) GetInner() error

GetInner is used by dropbox

func (*ChainError) GetMessage added in v3.3.43

func (e *ChainError) GetMessage() string

GetMessage is used by dropbox

func (*ChainError) Head added in v3.3.43

func (e *ChainError) Head() error

Head is the start of the linked list

func (*ChainError) Message added in v3.3.43

func (e *ChainError) Message() string

Message lets me simulate errgo

func (*ChainError) Next added in v3.3.43

func (e *ChainError) Next() error

Next is the next node in the linked list

func (*ChainError) Tail added in v3.3.43

func (e *ChainError) Tail() error

Tail is the end of the linked list

func (*ChainError) Underlying added in v3.3.43

func (e *ChainError) Underlying() error

Underlying lets me simulate errgo/facebook

type ErrorChain

type ErrorChain = ChainError

ErrorChain is type cast to ChainError for backwards compatibility This will be deprecated in future major release

type Loggable

type Loggable interface {
	Printf(string, ...interface{})
}

Loggable is anything the error loggers can print to

type Matcher

type Matcher interface {
	Matches(err error) bool
}

A Matcher detects if errors match some condition

type MatcherFunc

type MatcherFunc func(error) bool

MatcherFunc is used to match errors

func (MatcherFunc) Matches

func (m MatcherFunc) Matches(err error) bool

Matches should return true if the error matches the wrapped function

type MultiErr

type MultiErr = MultiError

MultiErr type cast MultiError for backward compatibility This will be deprecated in future major release

type MultiError added in v3.3.43

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

MultiError wraps multiple errors into one error string

func (*MultiError) Error added in v3.3.43

func (e *MultiError) Error() string

Jump to

Keyboard shortcuts

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