Documentation ¶
Overview ¶
Package checkpoint provides a way to decorate errors by some additional caller information which results in something similar to a stacktrace. Each error added to a checkpoint can be checked by errors.Is and retrieved by errors.As.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func From ¶
From just wraps an error by a new checkpoint which adds some caller information to the error. It returns nil, if err == nil.
func Wrap ¶
Wrap adds a checkpoint with some caller information from an error and accepts also another error which can further describe the checkpoint. Returns nil if prev == nil. If err is nil, it still creates a checkpoint. This allows for example to predefine some errors and use them later:
var( ErrSomethingSpecialWentWrong = errors.New("a very bad error") ) func someFunction() error { err := somethingOtherThatThrowsErrors() return checkpoint.Wrap(err, ErrSomethingSpecialWentWrong) } err := someFunction()
If used that way, you can still check with errors.Is() for the ErrSomethingSpecialWentWrong
if errors.Is(err, ErrSomethingSpecialWentWrong) { fmt.Println("The special error was thrown") } else { fmt.Println(err) }
but also for the error returned by somethingOtherThatThrowsErrors() (if you know what error it is). If the error in this example is nil, no checkpoint gets created.
Types ¶
This section is empty.