Documentation
¶
Overview ¶
Package errorx provide an enhanced error implements for go, allow with stacktraces and wrap another error.
Index ¶
- func As(err error, target any) bool
- func Cause(err error) error
- func Config(fns ...func(opt *ErrStackOpt))
- func E(msg string) error
- func Ef(tpl string, vars ...any) error
- func Err(msg string) error
- func Errf(tpl string, vars ...any) error
- func Errorf(tpl string, vars ...any) error
- func Has(err, target error) bool
- func Is(err, target error) bool
- func IsErrorX(err error) (ok bool)
- func IsFalse(result bool, fmtAndArgs ...any) error
- func IsIn[T comdef.ScalarType](value T, list []T, fmtAndArgs ...any) error
- func IsTrue(result bool, fmtAndArgs ...any) error
- func New(msg string) error
- func Newf(tpl string, vars ...any) error
- func NotIn[T comdef.ScalarType](value T, list []T, fmtAndArgs ...any) error
- func Previous(err error) error
- func Raw(msg string) error
- func Rawf(tpl string, vars ...any) error
- func ResetStdOpt()
- func SkipDepth(skipDepth int) func(opt *ErrStackOpt)
- func Stacked(err error) error
- func To(err error, target any) bool
- func TraceDepth(traceDepth int) func(opt *ErrStackOpt)
- func Traced(err error) error
- func Unwrap(err error) error
- func With(err error, msg string) error
- func WithOptions(msg string, fns ...func(opt *ErrStackOpt)) error
- func WithPrev(err error, msg string) error
- func WithPrevf(err error, tpl string, vars ...any) error
- func WithStack(err error) error
- func Withf(err error, tpl string, vars ...any) error
- func Wrap(err error, msg string) error
- func Wrapf(err error, tpl string, vars ...any) error
- type Causer
- type ErrList
- type ErrMap
- type ErrStackOpt
- type ErrorCoder
- type ErrorM
- type ErrorR
- type ErrorX
- func (e *ErrorX) CallerFunc() *Func
- func (s ErrorX) CallerPC() uintptr
- func (e *ErrorX) Cause() error
- func (e *ErrorX) Error() string
- func (e *ErrorX) Format(s fmt.State, verb rune)
- func (e *ErrorX) GoString() string
- func (e *ErrorX) Location() string
- func (e *ErrorX) Message() string
- func (s ErrorX) StackFrames() *runtime.Frames
- func (s ErrorX) StackLen() int
- func (e *ErrorX) StackString() string
- func (e *ErrorX) String() string
- func (e *ErrorX) Unwrap() error
- func (e *ErrorX) WriteTo(w io.Writer) (n int64, err error)
- type Errors
- type Func
- type Unwrapper
- type XErrorFace
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Cause ¶
Cause returns the first cause error by call err.Cause(). Otherwise, will returns current error.
func IsIn ¶ added in v0.6.2
func IsIn[T comdef.ScalarType](value T, list []T, fmtAndArgs ...any) error
IsIn value should be in the list, otherwise will return error
func NotIn ¶ added in v0.6.2
func NotIn[T comdef.ScalarType](value T, list []T, fmtAndArgs ...any) error
NotIn value should not be in the list, otherwise will return error
func To ¶
To try convert err to target, returns is result.
NOTICE: target must be ptr and not nil. alias of errors.As()
Usage:
var ex *errorx.ErrorX err := doSomething() if errorx.To(err, &ex) { fmt.Println(ex.GoString()) }
func WithOptions ¶
func WithOptions(msg string, fns ...func(opt *ErrStackOpt)) error
WithOptions new error with some option func
Types ¶
type Causer ¶
type Causer interface { // Cause returns the first cause error by call err.Cause(). // Otherwise, will returns current error. Cause() error }
Causer interface for get first cause error
type ErrorR ¶
type ErrorR interface { ErrorCoder fmt.Stringer IsSuc() bool IsFail() bool }
ErrorR useful for web service replay/response. code == 0 is successful. otherwise, is failed.
type ErrorX ¶
type ErrorX struct {
// contains filtered or unexported fields
}
ErrorX struct
TIPS:
fmt pkg call order: Format > GoString > Error > String
func (*ErrorX) CallerFunc ¶
CallerFunc returns the error caller func. if stack is nil, will return nil
func (ErrorX) CallerPC ¶
func (s ErrorX) CallerPC() uintptr
CallerPC the caller PC value in the stack. it is first frame.
func (*ErrorX) GoString ¶
GoString to GO string, contains stack information. printing an error with %#v will produce useful information.
func (*ErrorX) Location ¶
Location information for the caller func. more please see CallerFunc
Returns eg:
github.com/gookit/goutil/errorx_test.TestWithPrev(), errorx_test.go:34
func (ErrorX) StackFrames ¶
StackFrames stack frame list
func (*ErrorX) StackString ¶
StackString returns error stack string of current.
type Func ¶
Func struct