errx

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

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

Go to latest
Published: Nov 26, 2024 License: MIT Imports: 7 Imported by: 2

README

errx

An extension of Golang's error type that implements error tracking and encoding (kind & code).

C01. structure
type ErrX struct {
	// internal data: error array
	errors []error

	// fields for identification and api response
	Kind string `json:"kind"`
	Code string `json:"code"`
	Msg  string `json:"msg"`

	// optinal tracer
	Caller string // fn::file::line
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsErrX

func IsErrX(e error) (ok bool)

Types

type ErrX

type ErrX struct {

	// fields for identification and api response
	Kind string
	Code string
	Msg  string

	// optinal tracer
	Caller string // fn::file::line
	// contains filtered or unexported fields
}

func Eee

func Eee(options ...Option) (err *ErrX)

func Errorf

func Errorf(msg string, a ...any) (err *ErrX)

func FromE

func FromE(e error, args ...bool) (err *ErrX, ok bool)

checks if the input is an ErrX

func New

func New(e error, options ...Option) (err *ErrX)

func ParRun

func ParRun(funcs ...func() *ErrX) (err *ErrX)

func ParRunE

func ParRunE(funcs ...func() error) (err *ErrX)

func (*ErrX) Apply

func (self *ErrX) Apply(options ...Option) *ErrX

func (*ErrX) As

func (self *ErrX) As(target any) bool

iterate errors.As(self.errors[i], target): target = New(CustomError)

func (*ErrX) CopyErrors

func (self *ErrX) CopyErrors() (errs []error)

copy errors from the *ErrX

func (*ErrX) Equals

func (self *ErrX) Equals(other *ErrX) bool

compare the kind and code of two *ErrX

func (*ErrX) Error

func (self *ErrX) Error() string

func (*ErrX) Is

func (self *ErrX) Is(e error) bool

iterate errors.Is(self.errors[i], target): target = pkg.ErrorNotFound

func (*ErrX) IsNil

func (self *ErrX) IsNil() bool

func (*ErrX) MarshalErrors

func (self *ErrX) MarshalErrors() (msgs []json.RawMessage)

func (ErrX) MarshalJSON

func (self ErrX) MarshalJSON() ([]byte, error)

func (*ErrX) Size

func (self *ErrX) Size() int

size of self.errors

func (*ErrX) WithCaller

func (self *ErrX) WithCaller(skips ...int) *ErrX

func (*ErrX) WithCode

func (self *ErrX) WithCode(str string) *ErrX

func (*ErrX) WithDefault

func (self *ErrX) WithDefault(kind, code string, msg string, args ...any) *ErrX

func (*ErrX) WithErrorf

func (self *ErrX) WithErrorf(str string, args ...any) *ErrX

func (*ErrX) WithErrors

func (self *ErrX) WithErrors(errs ...error) *ErrX

func (*ErrX) WithKind

func (self *ErrX) WithKind(str string) *ErrX

func (*ErrX) WithMsg

func (self *ErrX) WithMsg(str string, args ...any) *ErrX

type Error

type Error interface {
	Error() string
	IsNil() bool
}

type Option

type Option func(*ErrX)

func Code

func Code(str string) Option

func Kind

func Kind(str string) Option

func Msg

func Msg(str string, args ...any) Option

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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