go.bigb.es/auxilia
Documentation
Index
- func AllDetails(err error) []any
- func As(err error, target any) bool
- func AsType(err error) (E, bool)
- func Cause(err error) error
- func Errorf(format string, args ...any) error
- func Find(err error, fn func(err error) bool) error
- func FindDetail(err error, dst any) bool
- func FindDetails(err error) []T
- func Is(err, target error) bool
- func IsCanceled(err error) bool
- func IsDeadline(err error) bool
- func IsTemporary(err error) bool
- func IsTimeout(err error) bool
- func Join(errs ...error) error
- func New(msg string) error
- func NewIllegalState() error
- func NewIllegalValue() error
- func NewImpossible() error
- func NewNotImplemented() error
- func NewUnsupported() error
- func Unwrap(err error) error
- func Walk(err error, fn func(err error) bool)
- func WithCancel(err error) error
- func WithCode(err error, code any) error
- func WithContext(err error, ctx context.Context, keys ...any) error
- func WithDeadline(err error) error
- func WithDetail(err error, detail any) error
- func WithDetails(err error, details ...any) error
- func WithHint(err error, hint string) error
- func WithIn(err error, category string) error
- func WithOwner(err error, owner string) error
- func WithPublic(err error, msg string) error
- func WithRequest(err error, req *http.Request, withBody bool) error
- func WithResponse(err error, res *http.Response, withBody bool) error
- func WithTags(err error, tags ...string) error
- func WithTemporary(err error) error
- func WithTime(err error, t time.Time) error
- func WithTimeout(err error) error
- func WithTrace(err error, traceID string) error
- func Wrap(err error, msg string) error
- func WrapContext(ctx context.Context, msg string) error
- func Wrapf(err error, format string, args ...any) error
- type CancelDetail
- type CodeDetail
- type ContextDetail
- type DeadlineDetail
- type HintDetail
- type IllegalState
- type IllegalValue
- type Impossible
- type InDetail
- type MergeStrategy
- type MergeStrategyProvider
- type NotImplemented
- type OwnerDetail
- type PublicDetail
- type RequestDetail
- type ResponseDetail
- type StacktraceDetail
- type TagsDetail
- type TemporaryDetail
- type TimeDetail
- type TimeoutDetail
- type TraceDetail
- type Unsupported
Functions
func AllDetails(err error) []any
AllDetails returns all details from the error tree as a flat list.
func As(err error, target any) bool
As finds the first error in err's tree that matches target and sets target to that error value. It is a convenience re-export of errors.As.
func AsType[E error](err error) (E, bool)
AsType finds the first error in err's tree that matches type E. It is a convenience re-export of errors.AsType.
func Cause(err error) error
Cause returns the innermost (root-cause) error by following the first unwrap path. For joined errors, it follows the first child.
func Errorf(format string, args ...any) error
Errorf creates a new error with a formatted message.
func Find(err error, fn func(err error) bool) error
Find returns the first error in the tree for which fn returns true (pre-order, depth-first). Returns nil if no error matches.
func FindDetail(err error, dst any) bool
FindDetail finds the first detail of type T in the error tree (pre-order, depth-first) and writes it into dst. dst must be a non-nil pointer. Returns true if found.
func FindDetails[T any](err error) []T
FindDetails finds all details of type T in the error tree.
func Is(err, target error) bool
Is reports whether any error in err's tree matches target. It is a convenience re-export of errors.Is.
func IsCanceled(err error) bool
IsCanceled reports whether the error is marked as canceled.
func IsDeadline(err error) bool
IsDeadline reports whether the error is marked as deadline exceeded.
func IsTemporary(err error) bool
IsTemporary reports whether the error is marked as temporary.
func IsTimeout(err error) bool
IsTimeout reports whether the error is marked as a timeout.
func Join(errs ...error) error
Join combines multiple errors into one. Nil errors are filtered out. Returns nil if no non-nil errors are provided. Unlike errors.Join, the returned error supports culpa formatting (fmt.Formatter, slog.LogValuer) and detail traversal.
func NewIllegalState() error
NewIllegalState creates an IllegalState error with a captured stacktrace.
func NewIllegalValue() error
NewIllegalValue creates an IllegalValue error with a captured stacktrace.
func NewImpossible() error
NewImpossible creates an Impossible error with a captured stacktrace.
func NewNotImplemented() error
NewNotImplemented creates a NotImplemented error with a captured stacktrace.
func NewUnsupported() error
NewUnsupported creates an Unsupported error with a captured stacktrace.
func Unwrap(err error) error
Unwrap returns the result of calling the Unwrap method on err, if err's type implements Unwrap. It is a convenience re-export of errors.Unwrap.
func Walk(err error, fn func(err error) bool)
Walk calls fn for each error in the tree (pre-order, depth-first). Handles both single-unwrap and multi-unwrap (joined) errors. Stops early if fn returns false.
func WithCancel(err error) error
WithCancel marks the error as a cancellation.
func WithContext(err error, ctx context.Context, keys ...any) error
WithContext attaches a ContextDetail with values extracted from ctx for the given keys.
func WithDeadline(err error) error
WithDeadline marks the error as a deadline exceeded.
func WithDetail(err error, detail any) error
WithDetail attaches a single detail to the error. Returns nil if err is nil.
func WithDetails(err error, details ...any) error
WithDetails attaches multiple details to the error in a single layer. Returns nil if err is nil.
func WithOwner(err error, owner string) error
WithOwner attaches an OwnerDetail.
func WithPublic(err error, msg string) error
WithPublic attaches a PublicDetail.
func WithRequest(err error, req *http.Request, withBody bool) error
WithRequest attaches a RequestDetail from an HTTP request.
func WithResponse(err error, res *http.Response, withBody bool) error
WithResponse attaches a ResponseDetail from an HTTP response.
func WithTemporary(err error) error
WithTemporary marks the error as temporary.
func WithTrace(err error, traceID string) error
WithTrace attaches a TraceDetail (distributed trace ID).
func Wrap(err error, msg string) error
Wrap wraps an existing error with a message and captures a stacktrace. Returns nil if err is nil.
func WrapContext(ctx context.Context, msg string) error
WrapContext wraps ctx.Err() with a message, auto-applying the appropriate marker (CancelDetail or DeadlineDetail). If context.Cause returns a different error than ctx.Err(), it is included in the chain. Returns nil if ctx.Err() is nil.
Types
type CancelDetail struct{}
CancelDetail marks an error as a cancellation.
func (CancelDetail) LogValue() slog.Value
LogValue implements slog.LogValuer.
type CodeDetail struct{ Code any }
CodeDetail carries a machine-readable error code or slug.
func (d CodeDetail) LogValue() slog.Value
LogValue implements slog.LogValuer.
type ContextDetail struct{ Values map[any]any }
ContextDetail carries key-value pairs extracted from context.
func (d ContextDetail) LogValue() slog.Value
LogValue implements slog.LogValuer.
type DeadlineDetail struct{}
DeadlineDetail marks an error as a deadline exceeded.
func (DeadlineDetail) LogValue() slog.Value
LogValue implements slog.LogValuer.
type HintDetail struct{ Hint string }
HintDetail carries a debugging hint.
func (d HintDetail) LogValue() slog.Value
LogValue implements slog.LogValuer.
type IllegalState struct{}
IllegalState signals an operation invoked in a wrong state.
func (IllegalState) Error() string
func (IllegalState) LogValue() slog.Value
type IllegalValue struct{}
IllegalValue signals a value that failed a precondition or invariant.
func (IllegalValue) Error() string
func (IllegalValue) LogValue() slog.Value
type Impossible struct{}
Impossible signals a code path that should never be reached (bug).
func (Impossible) Error() string
func (Impossible) LogValue() slog.Value
type InDetail struct{ Category string }
InDetail carries a feature category or domain.
func (d InDetail) LogValue() slog.Value
LogValue implements slog.LogValuer.
type MergeStrategy int
MergeStrategy defines how duplicate detail types are resolved when the same type appears in multiple layers of the error chain.
const ( // MergeOverwrite — outermost (latest) value wins. Default. MergeOverwrite MergeStrategy = iota // MergeCombine — values from all layers are collected into a slice. MergeCombine )
type MergeStrategyProvider interface { MergeStrategy() MergeStrategy }
MergeStrategyProvider is implemented by detail types that declare a non-default merge strategy.
type NotImplemented struct{}
NotImplemented signals an operation that exists but has no implementation yet.
func (NotImplemented) Error() string
func (NotImplemented) LogValue() slog.Value
type OwnerDetail struct{ Owner string }
OwnerDetail carries the name or email of the responsible team.
func (d OwnerDetail) LogValue() slog.Value
LogValue implements slog.LogValuer.
type PublicDetail struct{ Message string }
PublicDetail carries a message safe to show to end users.
func (d PublicDetail) LogValue() slog.Value
LogValue implements slog.LogValuer.
type RequestDetail struct { Method string URL string Header http.Header Body []byte }
RequestDetail carries an HTTP request snapshot.
func (d RequestDetail) LogValue() slog.Value
LogValue implements slog.LogValuer.
type ResponseDetail struct { StatusCode int Header http.Header Body []byte }
ResponseDetail carries an HTTP response snapshot.
func (d ResponseDetail) LogValue() slog.Value
LogValue implements slog.LogValuer.
type StacktraceDetail struct{ Trace stacktrace.Trace }
StacktraceDetail carries a captured stack trace. It uses MergeCombine so that traces from multiple wrap layers accumulate.
func (StacktraceDetail) MergeStrategy() MergeStrategy
MergeStrategy implements MergeStrategyProvider.
type TagsDetail struct{ Tags []string }
TagsDetail carries freeform string tags. Uses MergeCombine so tags accumulate across layers.
func (d TagsDetail) LogValue() slog.Value
LogValue implements slog.LogValuer.
func (TagsDetail) MergeStrategy() MergeStrategy
MergeStrategy implements MergeStrategyProvider.
type TemporaryDetail struct{}
TemporaryDetail marks an error as temporary (retryable).
func (TemporaryDetail) LogValue() slog.Value
LogValue implements slog.LogValuer.
type TimeDetail struct{ Time time.Time }
TimeDetail carries a timestamp associated with the error.
func (d TimeDetail) LogValue() slog.Value
LogValue implements slog.LogValuer.
type TimeoutDetail struct{}
TimeoutDetail marks an error as a timeout.
func (TimeoutDetail) LogValue() slog.Value
LogValue implements slog.LogValuer.
type TraceDetail struct{ TraceID string }
TraceDetail carries a distributed trace ID for correlation.
func (d TraceDetail) LogValue() slog.Value
LogValue implements slog.LogValuer.
type Unsupported struct{}
Unsupported signals an operation intentionally not supported.
func (Unsupported) Error() string
func (Unsupported) LogValue() slog.Value
Package culpa provides structured error handling with typed details, stacktrace capture, and chain traversal.