terrors

package module
v0.19.0 Latest Latest
Warning

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

Go to latest
Published: Feb 18, 2024 License: Apache-2.0 Imports: 10 Imported by: 14

README

terror

traceable golang error library 🧭

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ColorBrackets added in v0.7.0

func ColorBrackets(label string, value string) string

func ColorCode added in v0.10.0

func ColorCode(code int) string

func Errorf added in v0.4.0

func Errorf(format string, a ...any) *wrapError

Errorf formats according to a format specifier and returns the string as a value that satisfies error.

The returned error contains a Frame set to the caller's location and implements Formatter to show this information when printed with details.

func ExtractErrorDetail added in v0.7.0

func ExtractErrorDetail(err error) string

func FileNameOfPath added in v0.7.0

func FileNameOfPath(path string) string

func FormatCaller

func FormatCaller(pkg, path string, number int) string

func FormatCallerFromFrame added in v0.7.0

func FormatCallerFromFrame(frm Frame) string

func FormatErrorCaller

func FormatErrorCaller(err error, name string, verbose bool) string

func FormatJsonForDetail added in v0.7.0

func FormatJsonForDetail(b []byte, ignored []string, priority []string) (string, error)

func FullChainFormatter added in v0.12.0

func FullChainFormatter(kid error) string

func GetChain added in v0.12.0

func GetChain(err error) []error

func GetDeepest added in v0.19.0

func GetDeepest(err error) error

func GetDeepestTerror added in v0.19.0

func GetDeepestTerror(err error) *wrapError

func GetPackageAndFuncFromFuncName added in v0.7.0

func GetPackageAndFuncFromFuncName(pc string) (pkg, function string)

func InlineChainFormatter added in v0.12.0

func InlineChainFormatter(self func() string, kid error) string

func Into added in v0.7.0

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

Into finds the first error in err's chain that matches target type T, and if so, returns it.

Into is type-safe alternative to As.

func Mismatch added in v0.9.0

func Mismatch[T any](expected, actual T) *wrapError

func New

func New(text string) *wrapError

New returns an error that formats as the given text.

The returned error contains a Frame set to the caller's location and implements Formatter to show this information when printed with details.

func Wrap

func Wrap(err error, message string) *wrapError

Wrap error with message and caller.

func WrapWithCaller added in v0.3.0

func WrapWithCaller(err error, message string, frm int) *wrapError

func Wrapf

func Wrapf(err error, format string, a ...interface{}) *wrapError

Wrapf wraps error with formatted message and caller.

func ZeroLogCallerMarshalFunc added in v0.7.0

func ZeroLogCallerMarshalFunc(pc uintptr, file string, line int) string

Types

type Frame added in v0.4.0

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

A Frame contains part of a call stack.

func Caller added in v0.4.0

func Caller(skip int) Frame

Caller returns a Frame that describes a frame on the caller's stack. The argument skip is the number of frames to skip over. Caller(0) returns the frame for the caller of Caller.

func (Frame) Location added in v0.4.0

func (f Frame) Location() (pkg, function, file string, line int)

Location reports the file, line, and function of a frame.

The returned function may be "" even if file and line are not.

type Framer

type Framer interface {
	error
	Root() error
	Frame() Frame
	Detail() string
	Simple() string
}

func Cause2 added in v0.2.1

func Cause2(err error) (f Framer, r bool)

func FirstCause added in v0.7.0

func FirstCause(err error) (Framer, bool)

func ListCause added in v0.7.0

func ListCause(err error) ([]Framer, bool)

type Recovery added in v0.13.0

type Recovery struct {
	Suggestion string
	State      []any
}

type RecoveryInfo added in v0.18.0

type RecoveryInfo struct {
	DeepestSimpleErrorMessage string
	Suggestion                string
}

func IsRecoverable added in v0.13.0

func IsRecoverable(err error) (bool, *RecoveryInfo)

Jump to

Keyboard shortcuts

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