Documentation ¶
Index ¶
- func New(format string, args ...interface{}) error
- func ToError(val interface{}, options ...Option) error
- func Wrap(err error, options ...Option) error
- func WrapWithMessage(err error, format string, args ...interface{}) error
- func WrapWithRootMessage(err error, format string, args ...interface{}) error
- type Error
- type Frame
- type Option
- type StackTrace
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func New ¶
New creates a new sperr.Error with a stack It is recommended that `New` be called from the place where the actual error occurs and not do define errors. This is because sperr.Error is a stateful construct which also encapsulates the stacktrace at the time of creation.
For converting generic errors to sperr.Error the recommended usage pattern is sperr.Wrap or sperr.Wrapf
func Wrap ¶
Wrap creates a new sperr.Error if the `error` that is being wrapped is not an sperr.Error
When wrapping an error this also adds a stacktrace into the new `Error` object
func WrapWithMessage ¶
func WrapWithRootMessage ¶
Types ¶
type Error ¶
type Error struct {
// contains filtered or unexported fields
}
func (*Error) Cause ¶
Cause returns the underlying cause of this error. Maybe <nil> if this was created with New
func (*Error) Format ¶
All error values returned from this package implement fmt.Formatter and can be formatted by the fmt package. The following verbs are supported:
%s print the error. If the error has a Cause it will be printed recursively. %v see %s %+v detailed format - includes messages and detail. %#v Each Frame of the error's StackTrace will be printed in detail. %q a double-quoted string safely escaped with Go syntax
TODO: add Details for +
func (*Error) RootCause ¶
RootCause will retrieves the underlying root error in the error stack RootCause will recursively retrieve the topmost error that does not have a cause, which is assumed to be the original cause.
func (*Error) Stack ¶
func (e *Error) Stack() StackTrace
Stack retrieves the stack trace of the absolute underlying sperr.Error
type Frame ¶
type Frame uintptr
Frame represents a program counter inside a stack frame. For historical reasons if Frame is interpreted as a uintptr its value represents the program counter + 1.
func (Frame) Format ¶
Format formats the frame according to the fmt.Formatter interface.
%s source file %d source line %n function name %v equivalent to %s:%d
Format accepts flags that alter the printing of some verbs, as follows:
%+s function name and path of source file relative to the compile time GOPATH separated by \n\t (<funcname>\n\t<path>) %+v equivalent to %+s:%d
func (Frame) MarshalText ¶
MarshalText formats a stacktrace Frame as a text string. The output is the same as that of fmt.Sprintf("%+v", f), but without newlines or tabs.
type StackTrace ¶
type StackTrace []Frame
StackTrace is stack of Frames from innermost (newest) to outermost (oldest).
func (StackTrace) Format ¶
func (st StackTrace) Format(s fmt.State, verb rune)
Format formats the stack of Frames according to the fmt.Formatter interface.
%s lists source files for each Frame in the stack %v lists the source file and line number for each Frame in the stack
Format accepts flags that alter the printing of some verbs, as follows:
%+v Prints filename, function, and line number for each Frame in the stack.