errors

package
v1.1.5 Latest Latest
Warning

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

Go to latest
Published: May 17, 2018 License: Apache-2.0 Imports: 4 Imported by: 86

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 *ErrorChain 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 *ErrorChain 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 MultiErr 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(numWritten 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 ErrorChain

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

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

func (*ErrorChain) Cause

func (e *ErrorChain) Cause() error

Cause lets me simulate errgo

func (*ErrorChain) Error

func (e *ErrorChain) Error() string

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

func (*ErrorChain) GetInner

func (e *ErrorChain) GetInner() error

GetInner is used by dropbox

func (*ErrorChain) GetMessage

func (e *ErrorChain) GetMessage() string

GetMessage is used by dropbox

func (*ErrorChain) Head

func (e *ErrorChain) Head() error

Head is the start of the linked list

func (*ErrorChain) Message

func (e *ErrorChain) Message() string

Message lets me simulate errgo

func (*ErrorChain) Next

func (e *ErrorChain) Next() error

Next is the next node in the linked list

func (*ErrorChain) Tail

func (e *ErrorChain) Tail() error

Tail is the end of the linked list

func (*ErrorChain) Underlying

func (e *ErrorChain) Underlying() error

Underlying lets me simulate errgo/facebook

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 struct {
	// contains filtered or unexported fields
}

MultiErr wraps multiple errors into one error string

func (*MultiErr) Error

func (e *MultiErr) Error() string

Jump to

Keyboard shortcuts

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