errors

package
v1.5.4-beta2 Latest Latest
Warning

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

Go to latest
Published: Aug 17, 2021 License: Apache-2.0, Apache-2.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

View Source
const RootCodespace = "sdk"

RootCodespace is the codespace for all errors defined in this package

View Source
const (
	// SuccessABCICode declares an ABCI response use 0 to signal that the
	// processing was successful and no error is returned.
	SuccessABCICode = 0
)
View Source
const UndefinedCodespace = "undefined"

UndefinedCodespace when we explicitly declare no codespace

Variables

View Source
var (

	// ErrTxDecode is returned if we cannot parse a transaction
	ErrTxDecode = Register(RootCodespace, 2, "tx parse error")

	// ErrInvalidSequence is used the sequence number (nonce) is incorrect
	// for the signature
	ErrInvalidSequence = Register(RootCodespace, 3, "invalid sequence")

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

	// ErrInsufficientFunds is used when the account cannot pay requested amount.
	ErrInsufficientFunds = Register(RootCodespace, 5, "insufficient funds")

	// ErrUnknownRequest to doc
	ErrUnknownRequest = Register(RootCodespace, 6, "unknown request")

	// ErrInvalidAddress to doc
	ErrInvalidAddress = Register(RootCodespace, 7, "invalid address")

	// ErrInvalidPubKey to doc
	ErrInvalidPubKey = Register(RootCodespace, 8, "invalid pubkey")

	// ErrUnknownAddress to doc
	ErrUnknownAddress = Register(RootCodespace, 9, "unknown address")

	// ErrInvalidCoins to doc
	ErrInvalidCoins = Register(RootCodespace, 10, "invalid coins")

	// ErrOutOfGas to doc
	ErrOutOfGas = Register(RootCodespace, 11, "out of gas")

	// ErrMemoTooLarge to doc
	ErrMemoTooLarge = Register(RootCodespace, 12, "memo too large")

	// ErrInsufficientFee to doc
	ErrInsufficientFee = Register(RootCodespace, 13, "insufficient fee")

	// ErrTooManySignatures to doc
	ErrTooManySignatures = Register(RootCodespace, 14, "maximum number of signatures exceeded")

	// ErrNoSignatures to doc
	ErrNoSignatures = Register(RootCodespace, 15, "no signatures supplied")

	// ErrJSONMarshal defines an ABCI typed JSON marshalling error
	ErrJSONMarshal = Register(RootCodespace, 16, "failed to marshal JSON bytes")

	// ErrJSONUnmarshal defines an ABCI typed JSON unmarshalling error
	ErrJSONUnmarshal = Register(RootCodespace, 17, "failed to unmarshal JSON bytes")

	// ErrInvalidRequest defines an ABCI typed error where the request contains
	// invalid data.
	ErrInvalidRequest = Register(RootCodespace, 18, "invalid request")

	// ErrTxInMempoolCache defines an ABCI typed error where a tx already exists
	// in the mempool.
	ErrTxInMempoolCache = Register(RootCodespace, 19, "tx already in mempool")

	// ErrMempoolIsFull defines an ABCI typed error where the mempool is full.
	ErrMempoolIsFull = Register(RootCodespace, 20, "mempool is full")

	// ErrTxTooLarge defines an ABCI typed error where tx is too large.
	ErrTxTooLarge = Register(RootCodespace, 21, "tx too large")

	// ErrKeyNotFound defines an error when the key doesn't exist
	ErrKeyNotFound = Register(RootCodespace, 22, "key not found")

	// ErrWrongPassword defines an error when the key password is invalid.
	ErrWrongPassword = Register(RootCodespace, 23, "invalid account password")

	// ErrorInvalidSigner defines an error when the tx intended signer does not match the given signer.
	ErrorInvalidSigner = Register(RootCodespace, 24, "tx intended signer does not match the given signer")

	// ErrorInvalidGasAdjustment defines an error for an invalid gas adjustment
	ErrorInvalidGasAdjustment = Register(RootCodespace, 25, "invalid gas adjustment")

	// ErrInvalidHeight defines an error for an invalid height
	ErrInvalidHeight = Register(RootCodespace, 26, "invalid height")

	// ErrInvalidVersion defines a general error for an invalid version
	ErrInvalidVersion = Register(RootCodespace, 27, "invalid version")

	// ErrInvalidChainID defines an error when the chain-id is invalid.
	ErrInvalidChainID = Register(RootCodespace, 28, "invalid chain-id")

	// ErrInvalidType defines an error an invalid type.
	ErrInvalidType = Register(RootCodespace, 29, "invalid type")

	// ErrTxTimeoutHeight defines an error for when a tx is rejected out due to an
	// explicitly set timeout height.
	ErrTxTimeoutHeight = Register(RootCodespace, 30, "tx timeout height")

	// ErrUnknownExtensionOptions defines an error for unknown extension options.
	ErrUnknownExtensionOptions = Register(RootCodespace, 31, "unknown extension options")

	// ErrWrongSequence defines an error where the account sequence defined in
	// the signer info doesn't match the account's actual sequence number.
	ErrWrongSequence = Register(RootCodespace, 32, "incorrect account sequence")

	// ErrPackAny defines an error when packing a protobuf message to Any fails.
	ErrPackAny = Register(RootCodespace, 33, "failed packing protobuf message to Any")

	// ErrUnpackAny defines an error when unpacking a protobuf message from Any fails.
	ErrUnpackAny = Register(RootCodespace, 34, "failed unpacking protobuf message from Any")

	// ErrLogic defines an internal logic error, e.g. an invariant or assertion
	// that is violated. It is a programmer error, not a user-facing error.
	ErrLogic = Register(RootCodespace, 35, "internal logic error")

	// ErrConflict defines a conflict error, e.g. when two goroutines try to access
	// the same resource and one of them fails.
	ErrConflict = Register(RootCodespace, 36, "conflict")

	// ErrNotSupported is returned when we call a branch of a code which is currently not
	// supported.
	ErrNotSupported = Register(RootCodespace, 37, "feature not supported")

	// ErrNotFound defines an error when requested entity doesn't exist in the state.
	ErrNotFound = Register(RootCodespace, 38, "not found")

	// ErrIO should be used to wrap internal errors caused by external operation.
	// Examples: not DB domain error, file writing etc...
	ErrIO = Register(RootCodespace, 39, "Internal IO error")

	// ErrInternal define an error when
	ErrInternalStack = Register(RootCodespace, 40, "Internal Stack error")

	///ErrParams
	ErrParams = Register(RootCodespace, 41, "invalid params")

	///ErrInternal
	ErrInternal = Register(RootCodespace, 42, "Internal error")

	//ErrResponse
	ErrResponse = Register(RootCodespace, 43, "invalid response")

	ErrAccountNotExist = Register(RootCodespace, 47, "account not exist")

	ErrInsufficientMempoolFess = Register(RootCodespace, 51, "insufficient mempool fess")

	ErrAccountSetCoinFailed = Register(RootCodespace, 52, "set account coin failed")

	ErrModuleAccountSetCoinFailed = Register(RootCodespace, 53, "module account set coin failed")

	ErrRuxTxOutOfGas = Register(RootCodespace, 10101, "tx out of gas")

	ErrRecoverInRunTx = Register(RootCodespace, 10102, "recover in run tx")

	ErrInvalidParam = Register(RootCodespace, 10105, "invalid params")

	ErrCdcUnmarshalFailed = Register(RootCodespace, 10106, "cdc unmarshal failed")

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

Functions

func ABCIError

func ABCIError(codespace string, code uint32, log string) error

ABCIError will resolve an error code/log from an abci result into an error message. If the code is registered, it will map it back to the canonical error, so we can do eg. ErrNotFound.Is(err) on something we get back from an external API.

This should *only* be used in clients, not in the server side. The server (abci app / blockchain) should only refer to registered errors

func ABCIInfo

func ABCIInfo(err error, debug bool) (codespace string, code uint32, log string)

ABCIInfo returns the ABCI error information as consumed by the tendermint client. Returned codespace, 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, codespace UndefinedCodespace When not running in a debug mode all messages of errors that do not provide ABCICode information are replaced with generic "internal error". Errors without an ABCICode information as considered internal.

func IsOf

func IsOf(received error, targets ...error) bool

IsOf checks if a received error is caused by one of the target errors. It extends the errors.Is functionality to a list of errors.

func QueryResult

func QueryResult(err error) abci.ResponseQuery

QueryResult returns a ResponseQuery from an error. It will try to parse ABCI info from the error.

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

func Redact(err error) error

Redact replaces an error that is not initialized as an ABCI Error with a generic internal error instance. If the error is an ABCI Error, that error is simply returned.

func ResponseCheckTx

func ResponseCheckTx(err error, gw, gu uint64, debug bool, events []abci.Event) abci.ResponseCheckTx

ResponseCheckTx returns an ABCI ResponseCheckTx object with fields filled in from the given error and gas values.

func ResponseDeliverTx

func ResponseDeliverTx(err error, gw, gu uint64, debug bool, events []abci.Event) abci.ResponseDeliverTx

ResponseDeliverTx returns an ABCI ResponseDeliverTx object with fields filled in from the given error and gas values.

func WithType

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

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 functionality of formatting the input as specified.

Types

type Error

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 New

func New(codespace string, code uint32, desc string) *Error

func Register

func Register(codespace string, 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

func (e Error) ABCICode() uint32

func (Error) Codespace

func (e Error) Codespace() string

func (Error) Error

func (e Error) Error() string

func (*Error) Is

func (e *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.

func (Error) Wrap

func (e Error) Wrap(desc string) error

Wrap extends this error with an additional information. It's a handy function to call Wrap with sdk errors.

func (Error) Wrapf

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

Wrapf extends this error with an additional information. It's a handy function to call Wrapf with sdk errors.

Jump to

Keyboard shortcuts

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