errors

package module
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Aug 26, 2025 License: MIT Imports: 10 Imported by: 0

README

errors - Error handling primitives

Go Reference

This package is a kind of continuation of pkg/errors package with a little bit different approach to wrapping and inspecting errors.

Documentation

Overview

Package errors provides error handling primitives.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func As

func As(err error, target any) bool

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

func Kind(err error) error

func New

func New(msg 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

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

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]

Iter returns go1.23 iterator that wraps runtime.CallersFrames.

Jump to

Keyboard shortcuts

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