errors

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Jan 20, 2022 License: Apache-2.0 Imports: 2 Imported by: 0

Documentation

Index

Constants

View Source
const (
	CriticalUnknownError = CodeCritical + iota
	CriticalIOError
	CriticalFormatError
	CriticalHashError
)
View Source
const CodeSegment = 1000

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")
	ErrExecutionFail   = NewBase(ExecutionFailError, "ExecutionFail")
	ErrInterrupted     = NewBase(InterruptedError, "Interrupted")
)

Functions

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 FindCause added in v0.9.7

func FindCause(err error, cb func(err error) bool) error

func Is

func Is(err, target error) bool

Is checks whether err is caused by the target.

func IsCritical

func IsCritical(e error) bool

func IsCriticalCode

func IsCriticalCode(c Code) bool

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 ToString

func ToString(e error) string

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 (
	CodeSCORE Code = iota * CodeSegment
	CodeGeneral
	CodeService
	CodeConsensus
	CodeNetwork
	CodeBlock
	CodeServer
	CodeCritical
)
const (
	Success      Code = 0
	UnknownError Code = CodeGeneral + iota
	IllegalArgumentError
	UnsupportedError
	InvalidStateError
	NotFoundError
	InvalidNetworkError
	TimeoutError
	ExecutionFailError
	InterruptedError
)

func CodeOf

func CodeOf(e error) Code

func (Code) AttachTo

func (c Code) AttachTo(e error) error

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