errorutil

package
v0.2.16 Latest Latest
Warning

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

Go to latest
Published: Oct 21, 2024 License: MIT Imports: 8 Imported by: 482

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

func IsTimeout added in v0.0.62

func IsTimeout(err error) bool

IsTimeout checks if error is timeout error

Types

type ErrCallback

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

ErrCallback function to handle given error

type ErrWithFmt added in v0.0.7

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

ErrWithFmt is a simplified version of err holding a default format

func NewWithFmt added in v0.0.7

func NewWithFmt(fmt string) ErrWithFmt

func (*ErrWithFmt) Error added in v0.0.7

func (e *ErrWithFmt) Error()

func (*ErrWithFmt) Msgf added in v0.0.7

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