zerror

package
v1.7.12 Latest Latest
Warning

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

Go to latest
Published: Apr 27, 2024 License: MIT Imports: 7 Imported by: 12

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Is

func Is(err error, code ...ErrCode) bool

Is returns if err is Error and its code == code

func New

func New(code ErrCode, text string, w ...External) error

func Panic

func Panic(err error)

Panic if error is not nil, usually used in conjunction with TryCatch

func Reuse added in v1.3.0

func Reuse(err error) error

Reuse the error

func SupText deprecated added in v1.3.0

func SupText(err error, text string) error

Deprecated: please use zerror.With SupText returns the error text

func TryCatch

func TryCatch(fn func() error) (err error)

TryCatch exception capture

func Unwrap

func Unwrap(err error, code ErrCode) (error, bool)

Unwrap returns if err is Error and its code == code

func UnwrapErrors

func UnwrapErrors(err error) (errs []string)

UnwrapErrors Returns the current all error text

func UnwrapFirst added in v1.6.4

func UnwrapFirst(err error) (ferr error)

func With added in v1.3.2

func With(err error, text string, w ...External) error

With returns the inner error's text

func Wrap

func Wrap(err error, code ErrCode, text string, w ...External) error

Wrap wraps err with code

Types

type ErrCode

type ErrCode int32

ErrCode error code type

func UnwrapCode

func UnwrapCode(err error) (ErrCode, bool)

UnwrapCode Returns the current error code

func UnwrapCodes

func UnwrapCodes(err error) (codes []ErrCode)

UnwrapCodes Returns the current all error code

func UnwrapFirstCode added in v1.6.4

func UnwrapFirstCode(err error) (code ErrCode)

type Error

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

Error wraps err with code

func (*Error) Error

func (e *Error) Error() string

Error returns msg

func (*Error) Format

func (e *Error) Format(s fmt.State, verb rune)

Format formats the frame according to the fmt.Formatter interface

func (*Error) Stack

func (e *Error) Stack() string

Stack returns the stack callers as string

func (*Error) Unwrap

func (e *Error) Unwrap() error

Unwrap returns err inside

type External added in v1.4.6

type External func(err error) error

func WrapTag added in v1.4.6

func WrapTag(tag TagKind) External

type TagKind added in v1.4.6

type TagKind string
const (
	// Empty error
	None TagKind = ""
	// Internal errors, This means that some invariants expected by the underlying system have been broken
	Internal TagKind = "INTERNAL"
	// The operation was cancelled, typically by the caller
	Cancelled TagKind = "CANCELLED"
	// The client specified an invalid argument
	InvalidInput TagKind = "INVALID_INPUT"
	// Some requested entity was not found
	NotFound TagKind = "NOT_FOUND"
	// The caller does not have permission to execute the specified operation
	PermissionDenied TagKind = "PERMISSION_DENIED"
	// The request does not have valid authentication credentials for the operation
	Unauthorized TagKind = "UNAUTHORIZED"
)

func GetTag added in v1.4.6

func GetTag(err error) TagKind

func (TagKind) Text added in v1.7.4

func (t TagKind) Text(text string) error

func (TagKind) Wrap added in v1.4.9

func (t TagKind) Wrap(err error, text string) error

Jump to

Keyboard shortcuts

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