Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Unwrap ¶
Unwrap returns the original error if err is ErrWithContext, otherwise just returns err.
func Wrap ¶
Wrap adds stack trace info to err, if not already present. The return value will be of type ErrorWithContext. If err is nil, nil is returned instead.
Types ¶
type ErrorWithContext ¶
type ErrorWithContext struct { // Wrapped is the original error. Never nil. Wrapped error // CallStack captures the caller's stack at the time the ErrorWithContext was created; most recent // call first. CallStack []StackTrace // Context contains additional info from calls to Wrapf. The slice is in order of calls to Wrapf, // which Error() prints in reverse. Context []string }
ErrorWithContext contains an original error with context info and a stack trace. It implements the error interface.
func (*ErrorWithContext) Error ¶
func (err *ErrorWithContext) Error() string
func (*ErrorWithContext) Unwrap ¶
func (err *ErrorWithContext) Unwrap() error
Unwrap allows unwrapping an error as implemented in the `errors` standard library.
type StackTrace ¶
StackTrace identifies a filename (base filename only) and line number.
func CallStack ¶
func CallStack(height, startAt int) []StackTrace
CallStack returns a slice of StackTrace representing the current stack trace. The lines returned start at the depth specified by startAt: 0 means the call to CallStack, 1 means CallStack's caller, 2 means CallStack's caller's caller and so on. height means how many lines to include, counting deeper into the stack, with zero meaning to include all stack frames. If height is non-zero and there aren't enough stack frames, a placeholder value is used instead.
Suppose the stacktrace looks like: skerr.go:300 <- the call to runtime.Caller in skerr.CallStack alpha.go:123 beta.go:456 gamma.go:789 delta.go:123 main.go: 70 A typical call may look like skerr.CallStack(6, 1), which returns [{File:alpha.go, Line:123}, {File:beta.go, Line:456},...,
{File:main.go, Line:70}, {File:???, Line:1}], omitting the not-helpful reference to
CallStack and padding the response with a placeholder value, since the stack was not tall enough to show 6 items, starting at the second one.
func (*StackTrace) String ¶
func (st *StackTrace) String() string