Documentation ¶
Index ¶
- func Annotate(err error, msg string) error
- func Annotatef(err error, msg string, args ...interface{}) error
- func Cause(err error) error
- func DeferLogIfErr(errCallback func() error, l Loggable, msg string, args ...interface{})
- func Details(err error) string
- func Errorf(msg string, args ...interface{}) error
- func LogIfErr(err error, l Loggable, msg string, args ...interface{})
- func Matches(err error, f func(error) bool) bool
- func MatchesI(err error, m Matcher) bool
- func Message(err error) string
- func New(msg string) error
- func NewMultiErr(errs []error) error
- func Next(err error) error
- func PanicIfErr(err error, msg string, args ...interface{})
- func PanicIfErrWrite(numWritten int, err error)
- func Tail(err error) error
- func Wrap(head error, next error) error
- type ErrorChain
- func (e *ErrorChain) Cause() error
- func (e *ErrorChain) Error() string
- func (e *ErrorChain) GetInner() error
- func (e *ErrorChain) GetMessage() string
- func (e *ErrorChain) Head() error
- func (e *ErrorChain) Message() string
- func (e *ErrorChain) Next() error
- func (e *ErrorChain) Tail() error
- func (e *ErrorChain) Underlying() error
- type Loggable
- type Matcher
- type MatcherFunc
- type MultiErr
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Annotatef ¶
Annotatef adds a new formatf error in the chain that is some extra context about the error
func DeferLogIfErr ¶
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 Errorf ¶
Errorf is fmt.Errorf. Note returns error rather than *ErrorChain so that it matches fmt.Errorf signature
func Matches ¶
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 New ¶
New error. Note returns error rather than *ErrorChain so that it matches errors.New signature
func NewMultiErr ¶
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 ¶
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 ¶
PanicIfErr is useful if writing shell scripts. It will panic with a msg if err != nil
func PanicIfErrWrite ¶
PanicIfErrWrite is similar to PanicIfErr, but works well with io results that return integer+err
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) Error ¶
func (e *ErrorChain) Error() string
Error returns the error string of the tail of the linked list
func (*ErrorChain) GetMessage ¶
func (e *ErrorChain) GetMessage() string
GetMessage is used by dropbox
func (*ErrorChain) Next ¶
func (e *ErrorChain) Next() error
Next is the next node in 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 MatcherFunc ¶
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