errors

package
v0.0.11 Latest Latest
Warning

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

Go to latest
Published: Oct 27, 2022 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrUnknown         = NewBase(UnknownError, "UnknownError")
	ErrIllegalArgument = NewBase(IllegalArgumentError, "IllegalArgument")
	ErrInvalidState    = NewBase(InvalidStateError, "InvalidState")
	ErrUnsupported     = NewBase(UnsupportedError, "Unsupported")
	ErrNotFound        = NewBase(NotFoundError, "NotFound")
	ErrInvalidNetwork  = NewBase(InvalidNetworkError, "InvalidNetwork")
	ErrTimeout         = NewBase(TimeoutError, "Timeout")
)

Functions

func AsValue

func AsValue(ptr interface{}, err error) bool

AsValue checks whether the err is caused by specified typed error, and store it to the ptr.

func Errorc

func Errorc(code Code, msg string) error

func Errorcf

func Errorcf(code Code, f string, args ...interface{}) error

func Errorf

func Errorf(f string, args ...interface{}) error

func Is

func Is(err, target error) bool

Is checks whether err is caused by the target.

func New

func New(msg string) error

New makes an error including a stack without any code If you want to make base error without stack

func NewBase

func NewBase(code Code, msg string) *baseError

func WithCode

func WithCode(err error, code Code) error

func WithStack

func WithStack(e error) error

func Wrap

func Wrap(e error, msg string) error

func Wrapc

func Wrapc(e error, c Code, msg string) error

func Wrapcf

func Wrapcf(e error, c Code, f string, args ...interface{}) error

func Wrapf

func Wrapf(e error, f string, args ...interface{}) error

Types

type Code

type Code int
const (
	UnknownError Code = CodeGeneral + iota
	IllegalArgumentError
	UnsupportedError
	InvalidStateError
	NotFoundError
	InvalidNetworkError
	TimeoutError
)
const (
	CodeGeneral Code = iota * 1000
)

func CodeOf

func CodeOf(e error) Code

func (Code) Equals

func (c Code) Equals(e error) bool

func (Code) Errorf

func (c Code) Errorf(f string, args ...interface{}) error

func (Code) New

func (c Code) New(msg string) error

func (Code) Wrap

func (c Code) Wrap(e error, msg string) error

func (Code) Wrapf

func (c Code) Wrapf(e error, f string, args ...interface{}) error

type ErrorCoder

type ErrorCoder interface {
	error
	ErrorCode() Code
}

func CoderOf

func CoderOf(e error) (ErrorCoder, bool)

type Unwrapper

type Unwrapper interface {
	Unwrap() error
}

Unwrapper is interface to unwrap the error to get the origin error.

Jump to

Keyboard shortcuts

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