Documentation ¶
Index ¶
- Constants
- func Append(err error, errs ...error) error
- func AppendFlat(err error, errs ...error) error
- func GetStackTrace() string
- func Is(err interface{}, cause error) bool
- func New(class interface{}, options ...Option) error
- func NewDepth(class interface{}, startDepth int, options ...Option) error
- type Class
- type ClassProvider
- type Exception
- func (e *Exception) As(target interface{}) bool
- func (e *Exception) Decompose() map[string]interface{}
- func (e *Exception) Error() string
- func (e *Exception) Format(s fmt.State, verb rune)
- func (e *Exception) Is(target error) bool
- func (e *Exception) MarshalJSON() ([]byte, error)
- func (e *Exception) String() string
- func (e *Exception) UnmarshalJSON(contents []byte) error
- func (e *Exception) Unwrap() error
- type Frame
- type Multi
- type Option
- type StackPointers
- type StackStrings
- type StackTrace
- type StackTraceProvider
Constants ¶
const ( DefaultStackTraceStartDepth = 3 DefaultErrorStartDepth = 4 )
Defaults for start depth.
Variables ¶
This section is empty.
Functions ¶
func Append ¶
Append appends errors together, creating a multi-error.
Errors that are already multi-errors will be appended as is, creating a jagged error list.
To have a one-dimensional resulting error list, use `AppendFlat(...)`.
func AppendFlat ¶
AppendFlat appends errors together, creating a multi-error.
It differs from `Append(...)` in that it will flatten errors in the list that are already `Multi` errors, creating a one dimensional return list instead of a jagged return list.
func GetStackTrace ¶
func GetStackTrace() string
GetStackTrace is a utility method to get the current stack trace at call time.
func Is ¶
Is is a helper function that returns if an error is an ex.
It will handle if the err is an exception, a multi-error or a regular error. "Isness" is evaluated by if the class of the exception matches the class of the cause
func New ¶
New returns a new error with a call stack.
Pragma: this violates the rule that you should take interfaces and return concrete types intentionally; it is important for the semantics of typed pointers and nil for this to return an interface because (*Ex)(nil) != nil, but (error)(nil) == nil.
Types ¶
type Class ¶
type Class string
Class is a string wrapper that implements `error`. Use this to implement constant exception causes.
func (Class) MarshalJSON ¶
MarshalJSON implements json.Marshaler.
type ClassProvider ¶
type ClassProvider interface {
Class() error
}
ClassProvider is a type that can return an exception class.
type Exception ¶
type Exception struct { // Class disambiguates between errors, it can be used to identify the type of the error. Class error // Message adds further detail to the error, and shouldn't be used for disambiguation. Message string // Inner holds the original error in cases where we're wrapping an error with a stack trace. Inner error // StackTrace is the call stack frames used to create the stack output. StackTrace StackTrace }
Exception is an error with a stack trace.
It also can have an optional cause, it implements `Exception`
func (*Exception) Decompose ¶
Decompose breaks the exception down to be marshaled into an intermediate format.
func (*Exception) Error ¶
Error implements the `error` interface. It returns the exception class, without any of the other supporting context like the stack trace. To fetch the stack trace, use .String().
func (*Exception) Format ¶
Format allows for conditional expansion in printf statements based on the token and flags used.
%+v : class + message + stack %v, %c : class %m : message %t : stack
func (*Exception) Is ¶
Is returns true if the target error matches the Ex. Enables errors.Is on Ex classes when an error is wrapped using Ex.
func (*Exception) MarshalJSON ¶
MarshalJSON is a custom json marshaler.
func (*Exception) String ¶
String returns a fully formed string representation of the ex. It's equivalent to calling sprintf("%+v", ex).
func (*Exception) UnmarshalJSON ¶
UnmarshalJSON is a custom json unmarshaler.
type Frame ¶
type Frame uintptr
Frame represents a program counter inside a stack frame.
func (Frame) File ¶
File returns the full path to the file that contains the function for this Frame's pc.
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 path of source file relative to the compile time GOPATH %+v equivalent to %+s:%d
type Multi ¶
type Multi []error
Multi represents an array of errors.
func (Multi) Unwrap ¶
Unwrap returns an error from Error (or nil if there are no errors). This error returned will further support Unwrap to get the next error, etc.
The resulting error supports errors.As/Is/Unwrap so you can continue to use the stdlib errors package to introspect further.
This will perform a shallow copy of the errors slice. Any errors appended to this error after calling Unwrap will not be available until a new Unwrap is called on the multierror.Error.
func (Multi) WrappedErrors ¶
WrappedErrors implements something in errors.
type Option ¶
type Option func(*Exception)
Option is an exception option.
func OptInnerClass ¶
OptInnerClass sets an inner unwrapped exception. Use this if you don't want to include a strack trace for a cause.
func OptMessage ¶
func OptMessage(args ...interface{}) Option
OptMessage sets the exception message from a given list of arguments with fmt.Sprint(args...).
func OptMessagef ¶
OptMessagef sets the exception message from a given list of arguments with fmt.Sprintf(format, args...).
func OptStackTrace ¶
func OptStackTrace(stack StackTrace) Option
OptStackTrace sets the exception stack.
type StackPointers ¶
type StackPointers []uintptr
StackPointers is stack of uintptr stack frames from innermost (newest) to outermost (oldest).
func (StackPointers) Format ¶
func (st StackPointers) Format(s fmt.State, verb rune)
Format formats the stack trace.
func (StackPointers) MarshalJSON ¶
func (st StackPointers) MarshalJSON() ([]byte, error)
MarshalJSON is a custom json marshaler.
func (StackPointers) String ¶
func (st StackPointers) String() string
String returns a single string representation of the stack pointers.
func (StackPointers) Strings ¶
func (st StackPointers) Strings() []string
Strings dereferences the StackTrace as a string slice
type StackStrings ¶
type StackStrings []string
StackStrings represents a stack trace as string literals.
func (StackStrings) Format ¶
func (ss StackStrings) Format(s fmt.State, verb rune)
Format formats the stack trace.
func (StackStrings) MarshalJSON ¶
func (ss StackStrings) MarshalJSON() ([]byte, error)
MarshalJSON is a custom json marshaler.
func (StackStrings) String ¶
func (ss StackStrings) String() string
String returns a single string representation of the stack pointers.
func (StackStrings) Strings ¶
func (ss StackStrings) Strings() []string
Strings returns the stack strings as a string slice.
type StackTrace ¶
StackTrace is a stack trace provider.
type StackTraceProvider ¶
type StackTraceProvider interface {
StackTrace() StackTrace
}
StackTraceProvider is a type that can return an exception class.