e5

package module
v0.0.0-...-c066ba8 Latest Latest
Warning

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

Go to latest
Published: Sep 26, 2024 License: Apache-2.0 Imports: 8 Imported by: 37

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Check = CheckFunc(func(err error, args ...error) error {
	if err == nil {
		return nil
	}
	err = Wrap.With(args...)(err)
	return Throw(err)
})

Check is for error checking. if err is not nil, it will be wrapped with args then raised by Throw

View Source
var Wrap = WrapFunc(func(err error) error {
	return err
})
View Source
var WrapStacktrace = WrapFunc(func(prev error) error {
	if prev == nil {
		return nil
	}
	if stacktraceIncluded(prev) {
		return prev
	}

	var pcs _PCs
	runtime.Callers(2, pcs[:])

	stacktrace := &Stacktrace{
		handle: unique.Make(pcs),
	}
	err := Join(stacktrace, prev)
	return err
})

WrapStacktrace wraps current stacktrace

Functions

func Handle

func Handle(errp *error, args ...error)

Handle is for error handling

Error raised by Throw will be catched if any. If errp point to non-nil error, the error will be joined. If the result error is not nil, wrap functions will be applied. The result error will be assigned to errp if errp is not nil, otherwise Throw will be raised.

func TestWrapFunc

func TestWrapFunc(t *testing.T, fn WrapFunc)

TestWrapFunc tests a WrapFunc instance

func Throw

func Throw(err error, args ...error) error

Throw checks the error and if not nil, raise a panic which will be recovered by Handle

Types

type CheckFunc

type CheckFunc func(err error, args ...error) error

CheckFunc is the type of Check, see Check's doc for details

func (CheckFunc) With

func (c CheckFunc) With(moreArgs ...error) CheckFunc

With returns a new CheckFunc that do additional wrapping with moreWraps

func (CheckFunc) WithInfo

func (c CheckFunc) WithInfo(format string, args ...any) CheckFunc

type ErrInfo

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

ErrInfo represents a lazy-evaluaed formatted string

func (*ErrInfo) Error

func (i *ErrInfo) Error() string

Error implements error interface

type Error

type Error []error

Error represents multiple errors

func Join

func Join(err error, prev error) Error

Join joins two errors

func (Error) As

func (c Error) As(target interface{}) bool

As reports whether any error in the slice matches target. And if so, assign the first matching error to target

func (Error) Error

func (c Error) Error() string

Error implements error interface

func (Error) Is

func (c Error) Is(target error) bool

Is reports whether any error in the slice matches target

func (Error) Unwrap

func (c Error) Unwrap() []error

Unwrap returns all errors

type Stacktrace

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

Stacktrace represents call stack frames

func (*Stacktrace) Error

func (s *Stacktrace) Error() string

Error implements error interface

func (*Stacktrace) Is

func (s *Stacktrace) Is(err error) bool

type WrapFunc

type WrapFunc func(err error) error

WrapFunc wraps an error to form a new one.

Instances must follow these rules: if argument is nil, return value must be nil

func Close

func Close(c io.Closer) WrapFunc

Close returns a WrapFunc that closes the Closer

func Do

func Do(fn func()) WrapFunc

Do returns a WrapFunc that calls fn

func Ignore

func Ignore(err error) WrapFunc

Ignore returns a WrapFunc that returns nil if errors.Is(prev, err) is true

func IgnoreAs

func IgnoreAs(target any) WrapFunc

IgnoreAs returns a WrapFunc that returns nil if errors.As(prev, target) is true

func IgnoreContains

func IgnoreContains(str string) WrapFunc

IgnoreContains returns a WrapFunc that returns nil if prev.Error() contains str

func Info

func Info(format string, args ...any) WrapFunc

Info returns a WrapFunc that wraps an *ErrInfo error value

func TestingFatal

func TestingFatal(t *testing.T) WrapFunc

TestingFatal returns a WrapFunc that calls t.Fatal if error occur

func With

func With(err error) WrapFunc

With returns a WrapFunc that wraps an error value

func (WrapFunc) Assign

func (w WrapFunc) Assign(p *error)

func (WrapFunc) Error

func (w WrapFunc) Error() string

func (WrapFunc) With

func (w WrapFunc) With(args ...error) WrapFunc

func (WrapFunc) WithInfo

func (w WrapFunc) WithInfo(format string, args ...any) WrapFunc

Jump to

Keyboard shortcuts

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