Documentation
¶
Index ¶
- func As(err error, target any) bool
- func Is(err, target error) bool
- func New(title string) error
- func Stamp(err error) error
- func Wrap(err error, msg string) error
- func Wrapf(err error, format string, args ...any) error
- type Error
- func (e *Error) CausedBy(err error) *Error
- func (e *Error) Error() string
- func (e *Error) Is(err error) bool
- func (e *Error) String() string
- func (e *Error) Throw() error
- func (e *Error) Unwrap() error
- func (e *Error) WithDetail(detail string) *Error
- func (e *Error) WithDetailf(format string, args ...any) *Error
- func (e *Error) WithIdentifier(id int32) *Error
- func (e *Error) WithProperties(properties map[string]any) *Error
- func (e *Error) WithProperty(key string, value any) *Error
- type Trace
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Error ¶
type Error struct {
// The error title
Title string `json:"title" yaml:"title"`
// A numeric error code for programmatic handling
Identifier int32 `json:"identifier,omitempty" yaml:"identifier,omitempty"`
// Additional context as a list of strings
Details []string `json:"details,omitempty" yaml:"details,omitempty"`
// Key-value pairs for arbitrary metadata
Properties map[string]any `json:"properties,omitempty" yaml:"properties,omitempty"`
// The underlying error that caused this error
Cause error `json:"cause,omitempty" yaml:"cause,omitempty"`
// A trace of where the error was thrown
Stack []*Trace `json:"stack,omitempty" yaml:"stack,omitempty"`
}
Error is an enhanced error implementation that supports structured error information, error wrapping, stack traces, and additional metadata.
Error implements the standard error interface and can be used anywhere a standard Go error is expected.
func From ¶
From creates a new *Error from any error type. If the error is not an *Error, it creates a new error with title "unknown error" and sets the original error as the cause. If the error is an *Error, it returns a copy of the original error with the same title, identifier, details, properties.
func Intercept ¶
Intercept converts any error into an *Error type. If the provided error is already an *Error, it returns it as-is. Otherwise, it creates a new *Error wrapping the original error using From().
func (*Error) Error ¶
Error returns a formatted string representation of the error, including title, identifier, details, properties, location and cause.
func (*Error) Is ¶
Is compares this error with another error for equality. Two errors are considered equal if they have the same Title and Identifier.
func (*Error) Throw ¶
Throw adds a stack trace entry to the error and returns it as an error interface.
func (*Error) WithDetail ¶
WithDetail adds a detail string to the error for additional context.
func (*Error) WithDetailf ¶
WithDetailf adds a detail string to the error for additional context using a format string.
func (*Error) WithIdentifier ¶
WithIdentifier sets a numeric identifier for the error.
func (*Error) WithProperties ¶
WithProperties adds multiple key-value properties to the error.
type Trace ¶
type Trace struct {
// The function where the error occurred
Function string `json:"function,omitempty" yaml:"function,omitempty"`
// The file where the error occurred
File string `json:"file,omitempty" yaml:"file,omitempty"`
// The line where the error occurred
Line int `json:"line,omitempty" yaml:"line,omitempty"`
// The timestamp when trace was generated
Timestamp time.Time `json:"timestamp,omitempty" yaml:"timestamp,omitempty"`
}
Trace represents a single entry in an error's stack trace. It captures the location and time when an error was thrown or stamped.