Documentation ¶
Overview ¶
Based on https://godoc.org/github.com/samsarahq/go/oops and adapted to our function names and needs.
Index ¶
- func Cause(err error) error
- func Details(err error) string
- func Errorf(format string, a ...interface{}) error
- func Frames(err error) [][]Frame
- func Is(err, target error) bool
- func LogFields(err error) log.Fields
- func New(err string) error
- func Recover(p interface{}) error
- func Stack(err error) string
- func Trace(err error) error
- func Wrapf(err error, format string, a ...interface{}) error
- type Frame
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Cause ¶
Cause extracts the cause error of an altipla error. If err is not an altipla error, err itself is returned.
You can use Cause to check if an error is an expected error. For example, if you know than EOF error is fine, you can handle it with Cause.
func Errorf ¶
Errorf creates a new error with a reason and a stacktrace.
Use Errorf in places where you would otherwise return an error using fmt.Errorf or errors.New.
Note that the result of Errorf includes a stacktrace. This means that Errorf is not suitable for storing in global variables. For such errors, keep using errors.New.
func Frames ¶
Frames extracts all frames from an altipla error. If err is not an altipla error, nil is returned.
func Recover ¶
func Recover(p interface{}) error
Recover recovers from a panic in a defer. If there is no panic, Recover() returns nil. To use, call error.Recover(recover()) and compare the result to nil.
func Trace ¶
Trace annotates an error with a stacktrace.
Use Trace in places where you would otherwise return an error directly. If the error passed to Trace is nil, Trace will also return nil. This makes it safe to use in one-line return statements.
To check if a wrapped error is a specific error, such as io.EOF, you can extract the error passed in to Trace using Cause.
func Wrapf ¶
Wrapf annotates an error with a reason and a stacktrace. If err is nil, Wrapf returns nil.
Use Wrapf in places where you would otherwise return an error directly. If the error passed to Wrapf is nil, Wrapf will also return nil. This makes it safe to use in one-line return statements.
To check if a wrapped error is a specific error, such as io.EOF, you can extract the error passed in to Wrapf using Cause.