errors

package
v1.4.0 Latest Latest
Warning

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

Go to latest
Published: Aug 1, 2024 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Overview

Package errors replaces the standard Go package, adding the ability to attach a stack trace and annotations to an error

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func As

func As(err error, target any) bool

As delegates to the standard Go's errors.As function.

func Is

func Is(err, target error) bool

Is delegates to the standard Go's errors.Is function.

func Join

func Join(errs ...error) error

Join aggregates multiple errors into one. The stack traces of the original errors are discarded and a new stack trace is captured.

func New

func New(text string) error

New creates a new error, capturing the current stack location.

func Newc

func Newc(statusCode int, text string) error

Newc creates a new error with an HTTP status code, capturing the current stack location.

func Newcf

func Newcf(statusCode int, format string, a ...any) error

Newcf creates a new formatted error with an HTTP status code, capturing the current stack location.

func Newf

func Newf(format string, a ...any) error

Newf formats a new error, capturing the current stack location.

func RuntimeTrace

func RuntimeTrace(levels int) (file string, function string, line int, ok bool)

RuntimeTrace traces back by the amount of levels to retrieve the runtime information used for tracing.

func StatusCode

func StatusCode(err error) int

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 Trace

func Trace(err error) error

Trace appends the current stack location to the error's stack trace.

func TraceFull

func TraceFull(err error, level int) error

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

func TraceUp(err error, level int) error

TraceUp appends the level above the current stack location to the error's stack trace. Level 0 captures the location of the caller.

func Tracec

func Tracec(statusCode int, err error) error

Tracec appends the current stack location to the error's stack trace and sets the status code.

func Unwrap

func Unwrap(err error) error

Unwrap delegates to the standard Go's errors.Wrap function.

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.

Jump to

Keyboard shortcuts

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