errutil

package
v1.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 30, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Auto

func Auto()

Auto recovers from a panic, prints a rich stack trace, and exits.

func AutoHTTP

func AutoHTTP(next http.Handler) http.Handler

AutoHTTP returns an HTTP middleware that recovers from panics and renders a rich stack trace (in dev mode, as plain text; in any case the full trace is logged to stderr).

func EnableAuto

func EnableAuto()

EnableAuto enables automatic panic recovery (stub for future use).

func JoinErrors

func JoinErrors(errs ...error) error

JoinErrors merges multiple errors into a single MultiError. Returns nil if none.

func Print

func Print(err error)

Print renders a rich trace (file:line + source context) for a wrapped error, following the same format as Auto().

func Recover

func Recover(fn func())

Recover catches a panic in fn, prints a clean stack trace to stderr with file:line and function names, then exits with status 1. The panic always terminates the process.

func SetSkipPackages

func SetSkipPackages(pkgs ...string)

SetSkipPackages appends packages to the skip list for stack trace filtering.

func StackTrace

func StackTrace(err error) []uintptr

StackTrace unwraps err and returns the captured stack frames, if any.

func Trace

func Trace(msg string) error

Trace captures a stack trace at this point without modifying or wrapping an existing error. Useful in defers to annotate "where did this come from".

func WError

func WError(err error) error

WError is an opinionated Wrap that includes the stack trace directly in Error(). Use it when you always want the trace visible on every print.

func WithCode

func WithCode(code string, err error) error

WithCode wraps an error with a string code, e.g. [CODE] message.

func Wrap

func Wrap(err error) error

Wrap captures a stack trace at the call site and attaches it to err. Error() returns only the wrapped message. Use %+v or WError for full trace.

Types

type MultiError

type MultiError struct {
	Errors []error
}

MultiError aggregates multiple errors into one.

func (*MultiError) Append

func (e *MultiError) Append(errs ...error)

Append adds non-nil errors to the collection.

func (*MultiError) Error

func (e *MultiError) Error() string

Error returns a concatenated error message.

func (*MultiError) ErrorOrNil

func (e *MultiError) ErrorOrNil() error

ErrorOrNil returns the MultiError if errors exist, or nil.

func (*MultiError) HasErrors

func (e *MultiError) HasErrors() bool

HasErrors reports whether any errors were collected.

func (*MultiError) Unwrap

func (e *MultiError) Unwrap() []error

Unwrap returns the collected errors for errors.Is/As traversal.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL