errors

package
v1.3.12 Latest Latest
Warning

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

Go to latest
Published: Oct 18, 2023 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Overview

Package errors is replacement package for standard errors package. It attaches error code and stack information to the error object.

Index

Constants

View Source
const (
	CriticalUnknownError = CodeCritical + iota
	CriticalIOError
	CriticalFormatError
	CriticalHashError
	CriticalRerunError
)
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 Error added in v1.3.0

func Error(e error) error

Error returns wrapped error providing formatter to show error code and stacks properly.

func Errorc

func Errorc(c Code, msg string) error

func Errorcf

func Errorcf(c 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

func NewBase

func NewBase(c Code, msg string) *codedError

func ToString

func ToString(e error) string

func Unwrap added in v1.2.11

func Unwrap(err error) error

func WithCode

func WithCode(err error, c 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 ErrorWithStack added in v1.3.0

type ErrorWithStack interface {
	error
	StackTracer
}

type StackTracer added in v1.3.0

type StackTracer interface {
	StackTrace() errors.StackTrace
}

func StackTracerOf added in v1.3.0

func StackTracerOf(e error) (StackTracer, 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