errors

package module
v1.1.2 Latest Latest
Warning

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

Go to latest
Published: Jun 29, 2025 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func As

func As[T error](err error, target *T) bool

func Cause

func Cause(err error) error

func Errorf

func Errorf(format string, args ...any) error

func Into

func Into[T error](err error) (target T, ok bool)

func Is

func Is(err, target error) bool

func Join

func Join(errs ...error) error

func Kind added in v1.1.0

func Kind(err error) error

func Message added in v1.1.0

func Message(err error) string

func New

func New(s string) error

func Pack

func Pack(kind error, args ...any) error

Pack creates a new error with a given kind. List of valid function signatures:

Pack(kind error)
Pack(kind error, cause error)
Pack(kind error, cause error, s string)
Pack(kind error, cause error, format string, args ...any)
Pack(kind error, s string)
Pack(kind error, format string, args ...any)

func SetTrace

func SetTrace(n int64)

SetTrace sets the number of frames a stack trace will contain. If it's a zero then the stack trace won't be included in errors (default). The number of frames can't be negative.

func Trace

func Trace() bool

func Unwrap

func Unwrap(err error) error

func Wrap

func Wrap(err error, msg string) error

func Wrapf

func Wrapf(err error, format string, args ...any) error

Types

type Error

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

func (*Error) As added in v1.1.0

func (e *Error) As(target any) bool

func (*Error) Cause

func (e *Error) Cause() error

func (*Error) Error

func (e *Error) Error() string

func (*Error) Format

func (e *Error) Format(s fmt.State, verb rune)

Format formats the stack of Frames according to the fmt.Formatter interface.

%s    prints Error as is
%v    equivalent to %s
%q    prints Error in quotes

Accepts flags that alter the printing of some verbs, as follows:

%+s   prints Error and it's stack trace (if it has one)
%+v   equivalent to %+s

func (*Error) Is added in v1.1.0

func (e *Error) Is(target error) bool

func (*Error) Kind

func (e *Error) Kind() error

func (*Error) Message

func (e *Error) Message() string

func (*Error) StackTrace

func (e *Error) StackTrace() StackTrace

func (*Error) Unwrap

func (e *Error) Unwrap() []error

type Frame

type Frame runtime.Frame

func (*Frame) Format

func (f *Frame) Format(s fmt.State, verb rune)

Format formats the frame according to the fmt.Formatter interface.

%f    source file
%d    source line
%x    function name
%s    equivalent to %x\n\t%f:%d
%v    equivalent to %s

func (Frame) MarshalText

func (f Frame) MarshalText() ([]byte, error)

MarshalText formats a stacktrace frame as a text string. The output is the same as that of fmt.Sprintf("%x %f:%d", f).

func (*Frame) String

func (f *Frame) String() string

String formats a stacktrace frame as a text string. The output is the same as that of fmt.Sprintf("%x %f:%d", f).

type StackTrace

type StackTrace []uintptr

func (StackTrace) Format

func (st StackTrace) Format(s fmt.State, verb rune)

Format formats the stack of Frames according to the fmt.Formatter interface.

%s   prints filename, function, and line number for each Frame in the stack.
%v   equivalent to %s

func (StackTrace) Iter

func (st StackTrace) Iter() iter.Seq2[int, Frame]

Jump to

Keyboard shortcuts

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