Documentation ¶
Overview ¶
Package errs implements a detailed error object that provides stack traces with source locations, along with nested causes, if any.
Index ¶
- func Wrap(cause error) error
- type Causer
- type Error
- func (d *Error) Count() int
- func (d *Error) Detail(trimRuntime bool) string
- func (d Error) Error() string
- func (d *Error) ErrorOrNil() error
- func (d *Error) Format(state fmt.State, verb rune)
- func (d *Error) Message() string
- func (d *Error) StackTrace(trimRuntime bool) string
- func (d *Error) WrappedErrors() []error
- type ErrorWrapper
- type StackError
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Causer ¶
type Causer interface {
Cause() error
}
Causer defines the interface for determining the error the caused an error.
type Error ¶
type Error struct {
// contains filtered or unexported fields
}
Error holds the detailed error message.
Example ¶
package main import ( "fmt" "github.com/richardwilkes/toolbox/errs" ) func main() { var bad *int func() int { defer func() { if r := recover(); r != nil { if err, ok := r.(error); ok { fmt.Println(errs.NewWithCause("Caught panic", err)) } } }() return *bad // trigger a panic due to a nil pointer dereference }() }
Output:
func NewWithCause ¶
NewWithCause creates a new detailed error with the 'message' and underlying 'cause'.
func NewfWithCause ¶
NewfWithCause creates a new detailed error with an underlying 'cause' and using fmt.Sprintf() to format the message.
func WrapTyped ¶ added in v1.1.4
WrapTyped wraps an error and turns it into a detailed error. If error is already a detailed error or nil, it will be returned as-is. This method returns the error as an *Error. Use Wrap() to receive a generic error.
func (*Error) Detail ¶
Detail returns the fully detailed error message, which includes the primary message, the call stack, and potentially one or more chained causes.
func (*Error) ErrorOrNil ¶
ErrorOrNil returns an error interface if this Error represents one or more errors, or nil if it is empty.
func (*Error) Format ¶
Format implements the fmt.Formatter interface.
Supported formats:
- "%s" Just the message
- "%q" Just the message, but quoted
- "%v" The message plus a stack trace, trimmed of golang runtime calls
- "%+v" The message plus a stack trace
func (*Error) StackTrace ¶
StackTrace returns just the stack trace portion of the message.
func (*Error) WrappedErrors ¶
WrappedErrors returns the contained errors.
type ErrorWrapper ¶
ErrorWrapper contains methods for interacting with the wrapped errors.