Documentation
¶
Overview ¶
Package errctx allows for setting and retrieving contextual information on error objects
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Base ¶
Base returns the underlying error object that was prevoiusly wrapped in a call to Set. If the error did not come from Set it is returned as-is.
func Get ¶
func Get(err error, k interface{}) interface{}
Get retrieves the value associated with the key by a previous call to Set, which this error should have been returned from. Returns nil if the key isn't set, or if the error wasn't previously wrapped by Set at all.
This will traverse the error chain until it finds an error returned by Set that contains the key.
func Line ¶
Line returns the file and line number where Mark was first called on the error and a boolean indicating if any line was found.
func Mark ¶
Mark records the filename and line number that called Mark and sets it on the error. Future calls to Mark will NOT overwrite the previous line.
func MarkSkip ¶
MarkSkip is like Mark but allows you to skip an arbitrary amount of functions from the stack. Sending skip of 0 means to Mark the caller of this function.
Returns nil if the sent error is nil.
func Set ¶
Set takes in an error and one or more key/value pairs. It returns an error instance which can have Get called on it with one of those passed in keys to retrieve the associated value later.
Errors returned from Set are immutable. For example:
err := errors.New("ERR")
fmt.Println(errctx.Get(err, "foo")) // ""
err2 := errctx.Set(err, "foo", "a")
fmt.Println(errctx.Get(err2, "foo")) // "a"
err3 := errctx.Set(err2, "foo", "b")
fmt.Println(errctx.Get(err2, "foo")) // "a"
fmt.Println(errctx.Get(err3, "foo")) // "b"
Types ¶
This section is empty.