Documentation
¶
Overview ¶
Package errors provides error handling with lazy stack trace support. Drop-in replacement for github.com/pkg/errors using only standard library.
Stack traces are captured lazily: - Fast path: Only capture program counters ([]uintptr) when error is created - Slow path: Resolve to human-readable stack only when %+v is used
Usage:
import "github.com/donnyhardyanto/dxlib/errors"
err := errors.New("something failed")
err := errors.Wrap(err, "context")
fmt.Printf("%+v\n", err) // prints with stack trace
Index ¶
- Variables
- func Cause(err error) error
- func Errorf(format string, args ...any) error
- func New(message string) error
- func WithMessage(err error, message string) error
- func WithMessagef(err error, format string, args ...any) error
- func WithStack(err error) error
- func Wrap(err error, message string) error
- func Wrapf(err error, format string, args ...any) error
- type Frame
- type StackTrace
Constants ¶
This section is empty.
Variables ¶
Functions ¶
func New ¶
New creates error with message and captures stack trace. Stack is captured as raw pointers (fast), resolved only when %+v is used.
func WithMessage ¶
WithMessage wraps error with message but NO new stack trace. Use this when you want to add context without capturing a new stack. Returns nil if err is nil.
func WithMessagef ¶
WithMessagef wraps error with formatted message but NO new stack trace. Returns nil if err is nil.
func WithStack ¶
WithStack adds stack trace to existing error without additional message. Returns nil if err is nil.
Types ¶
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
type StackTrace ¶
type StackTrace []Frame
StackTrace is a 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.