errors

package
v0.12.0 Latest Latest
Warning

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

Go to latest
Published: Mar 12, 2019 License: Apache-2.0 Imports: 6 Imported by: 28

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (

	// ErrInternal represents a general case issue that cannot be
	// categorized as any of the below cases.
	// We start as 1 as 0 is reserved for non-errors
	ErrInternal = Register(1, "internal")

	// ErrUnauthorized is used whenever a request without sufficient
	// authorization is handled.
	ErrUnauthorized = Register(2, "unauthorized")

	// ErrNotFound is used when a requested operation cannot be completed
	// due to missing data.
	ErrNotFound = Register(3, "not found")

	// ErrInvalidMsg is returned whenever an event is invalid and cannot be
	// handled.
	ErrInvalidMsg = Register(4, "invalid message")

	// ErrInvalidModel is returned whenever a message is invalid and cannot
	// be used (ie. persisted).
	ErrInvalidModel = Register(5, "invalid model")

	// ErrDuplicate is returned when there is a record already that has the same
	// unique key/index used
	ErrDuplicate = Register(6, "duplicate")

	// ErrHuman is returned when application reaches a code path which should not
	// ever be reached if the code was written as expected by the framework
	ErrHuman = Register(7, "coding error")

	// ErrCannotBeModified is returned when something that is considered immutable
	// gets modified
	ErrCannotBeModified = Register(8, "cannot be modified")

	// ErrEmpty is returned when a value fails a not empty assertion
	ErrEmpty = Register(9, "value is empty")

	// ErrInvalidState is returned when an object is in invalid state
	ErrInvalidState = Register(10, "invalid state")

	// ErrInvalidType is returned whenever the type is not what was expected
	ErrInvalidType = Register(11, "invalid type")

	// ErrInsufficientAmount is returned when an amount of currency is insufficient, e.g. funds/fees
	ErrInsufficientAmount = Register(12, "insufficient amount")

	// ErrInvalidAmount stands for invalid amount of whatever
	ErrInvalidAmount = Register(13, "invalid amount")

	// ErrInvalidInput stands for general input problems indication
	ErrInvalidInput = Register(14, "invalid input")

	// ErrExpired stands for expired entities, normally has to do with block height expirations
	ErrExpired = Register(15, "expired")

	// ErrOverflow s returned when a computation cannot be completed
	// because the result value exceeds the type.
	ErrOverflow = Register(16, "an operation cannot be completed due to value overflow")

	// ErrPanic is only set when we recover from a panic, so we know to redact potentially sensitive system info
	ErrPanic = Register(111222, "panic")
)

Global error registry, codes 1-99 are reserved for global errors, 0 is reserved for non-errors

Functions

func NormalizePanic

func NormalizePanic(p interface{}) error

NormalizePanic converts a panic into a redacted error

We want the whole stack trace for logging but should show nothing over the ABCI interface....

func Recover

func Recover(err *error)

Recover takes a pointer to the returned error, and sets it upon panic

func Redact added in v0.12.0

func Redact(err error) error

Redact will replace all panic errors with a generic message

func WithType added in v0.12.0

func WithType(err error, obj interface{}) error

WithType is a helper to augment an error with a corresponding type message

Types

type Error added in v0.12.0

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

Error represents a root error.

Weave framework is using root error to categorize issues. Each instance created during the runtime should wrap one of the declared root errors. This allows error tests and returning all errors to the client in a safe manner.

All popular root errors are declared in this package. If an extension has to declare a custom root error, always use Register function to ensure error code uniqueness.

func Register added in v0.12.0

func Register(code uint32, description string) *Error

Register returns an error instance that should be used as the base for creating error instances during runtime.

Popular root errors are declared in this package, but extensions may want to declare custom codes. This function ensures that no error code is used twice. Attempt to reuse an error code results in panic.

Use this function only during a program startup phase.

func (Error) ABCICode added in v0.12.0

func (e Error) ABCICode() uint32

ABCICode returns the associated ABCICode

func (Error) ABCILog added in v0.12.0

func (e Error) ABCILog() string

ABCILog returns the stored description, same as Error()

func (Error) Error added in v0.12.0

func (e Error) Error() string

Error returns the stored description

func (*Error) Is added in v0.12.0

func (kind *Error) Is(err error) bool

Is check if given error instance is of a given kind/type. This involves unwrapping given error using the Cause method if available.

Any non weave implementation of an error is tested positive for being ErrInternal.

func (*Error) New added in v0.12.0

func (e *Error) New(description string) error

New returns a new error. Returned instance is having the root cause set to this error. Below two lines are equal

e.New("my description")
Wrap(e, "my description")

Allows sprintf format and vararg

func (*Error) Newf added in v0.12.0

func (e *Error) Newf(description string, args ...interface{}) error

Newf is basically New with formatting capabilities

type TMError

type TMError interface {
	ABCICode() uint32
	ABCILog() string
	// contains filtered or unexported methods
}

TMError is the tendermint abci return type with stack trace

func Wrap

func Wrap(err error, description string) TMError

Wrap extends given error with an additional information.

If the wrapped error does not provide ABCICode method (ie. stdlib errors), it will be labeled as internal error.

If err is nil, this returns nil, avoiding the need for an if statement when wrapping a error returned at the end of a function

func Wrapf added in v0.12.0

func Wrapf(err error, format string, args ...interface{}) TMError

Wrapf extends given error with an additional information.

This function works like Wrap function with additional funtionality of formatting the input as specified.

Jump to

Keyboard shortcuts

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