errors

package
v0.14.0 Latest Latest
Warning

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

Go to latest
Published: Apr 10, 2019 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// 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")

	// ErrCurrency is returned whenever an operation cannot be completed
	// due to a currency issues.
	ErrCurrency = Register(17, "currency")

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

Functions

func ABCIInfo added in v0.12.1

func ABCIInfo(err error, debug bool) (uint32, string)

ABCIInfo returns the ABCI error information as consumed by the tenderemint client. Returned code and log message should be used as a ABCI response. Any error that does not provide ABCICode information is categorized as error with code 1. When not running in a debug mode all messsages of errors that do not provice ABCICode infromation are replaced with generic "internal error". Errors without an ABCICode information as considered internal.

func Recover

func Recover(err *error)

Recover captures a panic and stop its propagation. If panic happens it is transformed into a ErrPanic instance and assigned to given error. Call this function using defer in order to work as expected.

func Redact added in v0.12.0

func Redact(err error, debug bool) error

Redact replace all errors that do not initialize with a weave error with a generic internal error instance. This function is supposed to hide implementation details errors and leave only those that weave framework originates.

This is a no-operation function when running in debug mode.

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

func Wrap

func Wrap(err error, description string) error

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{}) error

Wrapf extends given error with an additional information.

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

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

func (Error) Error added in v0.12.0

func (e Error) Error() string

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.

Jump to

Keyboard shortcuts

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