errors

package
v0.0.0-...-b028674 Latest Latest
Warning

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

Go to latest
Published: Jun 20, 2024 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func As

func As(err error, target any) bool

As finds the first error in err's tree that matches target, and if one is found, sets target to that error value and returns true. Otherwise, it returns false.

This calls errors.As under the hood, and is intended to allow this package to serve as a drop-in replacement for errors.

func Is

func Is(err, target error) bool

Is reports whether any error in err's tree matches target.

This calls errors.Is under the hood, and is intended to allow this package to serve as a drop-in replacement for errors.

func Join

func Join(errs ...error) error

Join returns an error that wraps the given errors. Any nil error values are discarded. Join returns nil if every value in errs is nil.

This calls errors.Join under the hood, and is intended to allow this package to serve as a drop-in replacement for errors.

Types

type Error

type Error struct {
	// contains filtered or unexported fields
}

Error is an error type with embedded stack trace and optional logging attributes.

func Errorf

func Errorf(msg string, v ...any) *Error

Errorf returns a new formatted error value with embedded location and stack trace.

func New

func New(text string) *Error

New returns a new error value with embedded location and stack trace.

func (*Error) Error

func (e *Error) Error() string

Error conforms to the stdlib error interface, allowing you to return this as an error value.`

func (*Error) Fields

func (e *Error) Fields() []any

Fields returns a []any of any fields added to the error using Error.With with each key prefixed with `err_` to set them apart from other logged attributes.

func (*Error) Location

func (e *Error) Location() *Location

Location returns the source location where the error was created.

func (*Error) Stack

func (e *Error) Stack() Stack

Stack returns the callstack for the given error.

func (*Error) Unwrap

func (e *Error) Unwrap() error

Unwrap allows this error to be unwrapped such that errors embedded using Errorf with the `%w` print verb can be extracted.

func (*Error) With

func (e *Error) With(field string, value any) *Error

With adds a field and a value to this error that will be logged alongside it in any message using the srv package. This is a fluent interface and can be called in a chain to add multiple values

type Location

type Location struct {
	File     string
	Function string
	Line     int
}

Location represents a single frame in the call stack.

func (*Location) Format

func (l *Location) Format(state fmt.State, verb rune)

Format implements fmt.Formatter, allowing a Location to be printed using the following print verbs:

  • %s, %v gives `<file>:<line>`
  • %q gives `"<file>:<line>"`
  • %+v gives `<file>:<line>(<function>)`
  • %#v gives `errors.Location{File: "<file>", Function: "<function>", Line: <line>}`

func (*Location) String

func (l *Location) String() string

String prints a Location in the form of `<file>:<line>`

type Stack

type Stack []*Location

Stack is the call stack from the location of the error up to main.main()

func (Stack) String

func (s Stack) String() string

String renders the call stack in the format of:

<function>(<file>:<line>) ► [...]

Jump to

Keyboard shortcuts

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