errorutil

package
v0.0.19 Latest Latest
Warning

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

Go to latest
Published: May 25, 2023 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ShowStackTrace bool = false

ShowStackTrace in Error Message

Functions

func IsAny

func IsAny(err error, errxx ...error) bool

IsAny checks if err is not nil and matches any one of errxx errors if match successful returns true else false Note: no unwrapping is done here

Types

type ErrCallback

type ErrCallback func(level ErrorLevel, err string, tags ...string)

ErrCallback function to handle given error

type ErrWithFmt

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

ErrWithFmt is a simplified version of err holding a default format

func NewWithFmt

func NewWithFmt(fmt string) ErrWithFmt

func (*ErrWithFmt) Error

func (e *ErrWithFmt) Error()

func (*ErrWithFmt) Msgf

func (e *ErrWithFmt) Msgf(args ...any) error

Wrapf wraps given message

type Error

type Error interface {
	// WithTag assigns tag[s] to Error
	WithTag(tag ...string) Error
	// WithLevel assigns given ErrorLevel
	WithLevel(level ErrorLevel) Error
	// Error is interface method of 'error'
	Error() string
	// Wraps existing error with errors (skips if passed error is nil)
	Wrap(err ...error) Error
	// Msgf wraps error with given message
	Msgf(format string, args ...any) Error
	// Equal Checks Equality of errors
	Equal(err ...error) bool
	// WithCallback execute ErrCallback function when Error is triggered
	WithCallback(handle ErrCallback) Error
}

Error is enriched version of normal error with tags, stacktrace and other methods

func New

func New(format string, args ...any) Error

New

func NewWithErr

func NewWithErr(err error) Error

func NewWithTag

func NewWithTag(tag string, format string, args ...any) Error

NewWithTag creates an error with tag

func WrapfWithNil

func WrapfWithNil(err error, format string, args ...any) Error

WrapfWithNil returns nil if error is nil but if err is not nil wraps error with given msg unlike errors.Wrapf

func WrapwithNil

func WrapwithNil(err error, errx ...error) Error

WrapwithNil returns nil if err is nil but wraps it with given errors continuously if it is not nil

type ErrorLevel

type ErrorLevel uint
const (
	Panic ErrorLevel = iota
	Fatal
	Runtime // Default
)

func (ErrorLevel) String

func (l ErrorLevel) String() string

Jump to

Keyboard shortcuts

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