errorz

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Dec 3, 2024 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 any](err error) (T, bool)

As provides a more handy implementation of "errors.As" using generics.

func Assertf

func Assertf(cond bool, format string, a ...any)

Assertf is like MustErrorf if cond is false, does nothing otherwise.

func Errorf

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

Errorf creates an error and wraps it.

func IgnoreClose

func IgnoreClose(c io.Closer)

IgnoreClose calls Close on the given io.Closer, ignoring the returned error. Handy for the defer Close pattern.

func MaybeMustWrap

func MaybeMustWrap(err error, outerErrs ...error)

MaybeMustWrap is like MustWrap, but does nothing if called with a nil error.

func MaybeWrap

func MaybeWrap(err error, outerErrs ...error) error

MaybeWrap is like Wrap, but returns nil if called with a nil error.

func MaybeWrapRecover

func MaybeWrapRecover(r any, outerErrs ...error) error

MaybeWrapRecover is like WrapRecover but returns nil if called with a nil value.

func MustClose

func MustClose(c io.Closer)

MustClose calls Close on the given io.Closer, panicking in case of error. Handy for the defer Close pattern.

func MustErrorf

func MustErrorf(format string, a ...any)

MustErrorf is like Errorf but panics with the wrapped error instead of returning it.

func MustWrap

func MustWrap(innerErr error, outerErrs ...error)

MustWrap is like Wrap, but panics with the wrapped error instead of returning it.

func SDump

func SDump(err error) string

SDump converts the error to a string representation for debug purposes.

func Wrap

func Wrap(err error, outerErrs ...error) error

Wrap wraps the given errors.

func WrapRecover

func WrapRecover(r any, outerErrs ...error) error

WrapRecover takes a recovered value and converts it to a wrapped error.

Types

type AsHelper

type AsHelper interface {
	As(any) bool
}

AsHelper describes a method called by errors.As to allow customizing its logic.

type Frame

type Frame struct {
	Summary       string `json:"summary,omitempty"`
	Location      string `json:"location,omitempty"`
	ShortLocation string `json:"shortLocation,omitempty"`
	Package       string `json:"fullPackage,omitempty"`
	ShortPackage  string `json:"package,omitempty"`
	Function      string `json:"function,omitempty"`
	FileAndLine   string `json:"fileAndLine,omitempty"`
	File          string `json:"file,omitempty"`
	Line          int    `json:"line,omitempty"`
}

Frame describes a frame.

func NewFrame

func NewFrame(frameFunction string, file string, line int) *Frame

NewFrame initializes a new frame.

type Frames

type Frames []*Frame

Frames describes a stack of frames.

func GetFrames

func GetFrames(err error) Frames

GetFrames returns the frames from the error, or the current frames the error is not wrapped or is nil.

func (Frames) ToSummaries

func (f Frames) ToSummaries() []string

ToSummaries converts the frames to a slice of frame summaries.

type IsHelper

type IsHelper interface {
	Is(error) bool
}

IsHelper describes a method called by errors.Is to allow customizing its logic.

type UnwrapMulti

type UnwrapMulti interface {
	Unwrap() []error
}

UnwrapMulti describes a method which returns multiple errors.

type UnwrapSingle

type UnwrapSingle interface {
	Unwrap() error
}

UnwrapSingle describes a method which returns a single error.

Jump to

Keyboard shortcuts

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