Documentation ¶
Overview ¶
Package errors replaces the standard Go package, adding the ability to attach a stack trace and annotations to an error
Index ¶
- func As(err error, target any) bool
- func Is(err, target error) bool
- func Join(errs ...error) error
- func New(text string) error
- func Newc(statusCode int, text string) error
- func Newcf(statusCode int, format string, a ...any) error
- func Newf(format string, a ...any) error
- func RuntimeTrace(levels int) (file string, function string, line int, ok bool)
- func StatusCode(err error) int
- func Trace(err error) error
- func TraceFull(err error, level int) error
- func TraceUp(err error, level int) error
- func Tracec(statusCode int, err error) error
- func Unwrap(err error) error
- type TracedError
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Join ¶
Join aggregates multiple errors into one. The stack traces of the original errors are discarded and a new stack trace is captured.
func Newc ¶
Newc creates a new error with an HTTP status code, capturing the current stack location.
func Newcf ¶
Newcf creates a new formatted error with an HTTP status code, capturing the current stack location.
func RuntimeTrace ¶
RuntimeTrace traces back by the amount of levels to retrieve the runtime information used for tracing.
func StatusCode ¶
StatusCode returns the HTTP status code associated with an error. It is the equivalent of Convert(err).StatusCode. If not specified, the default status code is 500.
func TraceFull ¶
TraceFull appends the full stack to the error's stack trace, starting at the indicated level. Level 0 captures the location of the caller.
func TraceUp ¶
TraceUp appends the level above the current stack location to the error's stack trace. Level 0 captures the location of the caller.
Types ¶
type TracedError ¶
type TracedError struct { StatusCode int // contains filtered or unexported fields }
TracedError is a standard Go error augmented with a stack trace.
func Convert ¶
func Convert(err error) *TracedError
Convert converts an error to one that supports stack tracing. If the error already supports this, it is returned as it is. Note: Trace should be called to include the error's trace in the stack.
func (*TracedError) Format ¶
func (e *TracedError) Format(s fmt.State, verb rune)
Format the error based on the verb and flag.
func (*TracedError) MarshalJSON ¶
func (e *TracedError) MarshalJSON() ([]byte, error)
MarshalJSON marshals the error to JSON.
func (*TracedError) String ¶
func (e *TracedError) String() string
String returns a string representation of the error.
func (*TracedError) UnmarshalJSON ¶
func (e *TracedError) UnmarshalJSON(data []byte) error
UnmarshalJSON unmarshals the erro from JSON.
func (*TracedError) Unwrap ¶
func (e *TracedError) Unwrap() error
Unwrap returns the underlying error.