pear

package module
v0.0.5 Latest Latest
Warning

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

Go to latest
Published: Feb 9, 2025 License: MIT Imports: 10 Imported by: 9

README

pear

a pear is a perfect error

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func As

func As(err error, target any) bool

drop-in replacement for errors.As

func Dump

func Dump(e error) string

func Errorf

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

func Is

func Is(err, target error) bool

drop-in replacement for errors.Is

func IsPear

func IsPear(e error) bool

func Join

func Join(errs ...error) error

drop-in replacement for errors.Join

func NicePanic

func NicePanic(w io.Writer)

Types

type Error

type Error interface {
	Error() string
	Wrap(error)
	Unwind() []*Pear
	Trace() []ErrorWithStackFrame
	Dump() string
}

an Error is an error with a stack trace.

type ErrorWithStackFrame

type ErrorWithStackFrame struct {
	Message string `json:"msg"`
	*StackFrame
}

ErrorWithStackFrame is an error with a stack frame

type MultiError

type MultiError interface {
	Error
	Unwrap() []error
}

a MultiError is an error made up of a list of errors

type Multipear

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

Multipear is here to support errors.Join

func NewMultiPear

func NewMultiPear(errs ...*Pear) *Multipear

func (*Multipear) As

func (m *Multipear) As(target any) bool

func (*Multipear) Dump

func (m *Multipear) Dump() string

func (*Multipear) Error

func (m *Multipear) Error() string

func (*Multipear) Is

func (m *Multipear) Is(target error) bool

func (*Multipear) Trace

func (m *Multipear) Trace() []ErrorWithStackFrame

func (*Multipear) Unwind

func (m *Multipear) Unwind() []*Pear

func (*Multipear) Unwrap

func (m *Multipear) Unwrap() []error

func (*Multipear) Wrap

func (m *Multipear) Wrap(e error)

type Pear

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

Pear is a perfect error

func AsPear

func AsPear(e error, offset int) *Pear

AsPear casts an error to a *Pear, or does nothing if it already is one

func Defer

func Defer(msg string) *Pear

func New

func New(msg string) *Pear

drop-in replacement for errors.New

func (*Pear) Dump

func (p *Pear) Dump() string

Dump a JSON formatted output of the stack trace

func (*Pear) Error

func (p *Pear) Error() string

func (*Pear) Stack

func (p *Pear) Stack(offset int) *StackFrame

Stack produces (or just returns) a StackFrame for a *Pear

func (*Pear) Throw

func (p *Pear) Throw(offset int) *Pear

func (*Pear) Trace

func (p *Pear) Trace() []ErrorWithStackFrame

Trace returns all the [StackFrame]s from the *Pear, down through its descendants

func (*Pear) Unwind

func (p *Pear) Unwind() []*Pear

Unwind unwraps *Pear recursively until there are no more children

func (*Pear) Unwrap

func (p *Pear) Unwrap() error

func (*Pear) Wrap

func (p *Pear) Wrap(e error)

Wrap wraps an error, making it the child of our *Pear

type SingleError

type SingleError interface {
	Error
	Unwrap() error
	Stack(int) *StackFrame
}

a SingleError is the most common type of error

type StackFrame

type StackFrame struct {
	Func           string  `json:"func"`
	File           string  `json:"file"`
	Line           int     `json:"line"`
	ProgramCounter uintptr `json:"-"`
}

A StackFrame is a record of program execution.

Jump to

Keyboard shortcuts

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