Documentation ¶
Overview ¶
Package errors provides error creation and matching for all wallet systems. It is imported as errors and takes over the roll of the standard library errors package.
Index ¶
- Variables
- func As(err error, target any) bool
- func E(args ...any) error
- func Errorf(format string, args ...any) error
- func Is(err, target error) bool
- func Join(errs ...error) error
- func New(text string) error
- func Stacks(err error) [][]byte
- func WithStack(args ...any) error
- type Error
- type Kind
- type Op
Constants ¶
This section is empty.
Variables ¶
var Separator = ":\n\t"
Separator is inserted between nested errors when formatting as strings. The default separator produces easily readable multiline errors. Separator may be modified at init time to create error strings appropriate for logging errors on a single line.
Functions ¶
func As ¶
As attempts to assign the error pointed to by target with the first error in err's error chain with a compatible type. Returns true if target is assigned.
func E ¶
E creates an *Error from one or more arguments.
Each argument type is inspected when constructing the error. If multiple args of similar type are passed, the final arg is recorded. The following types are recognized:
errors.Op The operation, method, or RPC which was invoked. errors.Kind The class of error. string Description of the error condition. String types populate the Err field and overwrite, and are overwritten by, other arguments which implement the error interface. error The underlying error. If the error is an *Error, the Op and Kind will be promoted to the newly created error if not set to another value in the args.
If another *Error is passed as an argument and no other arguments differ from the wrapped error, instead of wrapping the error, the errors are collapsed and fields of the passed *Error are promoted to the returned error.
Panics if no arguments are passed.
func New ¶
New creates a simple error from a string. New is identical to "errors".New from the standard library.
Types ¶
type Error ¶
Error describes an error condition raised within the wallet process. Errors may optionally provide details regarding the operation and class of error for assistance in debugging and runtime matching of errors.
func (*Error) As ¶
As implements the interface to work with the standard library's errors.As. If target points to an *Error (i.e. target has type **Error), target is assigned e and As returns true. If target points to a Kind and e's Kind is not Other, target is assigned the kind and As returns true. Else, target is not assinged and As returns false.
func (*Error) Is ¶
Is implements the interface to work with the standard library's errors.Is. If target is an *Error, Is returns true if every top-level and wrapped non-zero fields of target are equal to the same fields of e. If target is a Kind, Is returns true if the Kinds match and are nonzero. Else, Is returns false.
type Kind ¶
type Kind int
Kind describes the class of error.
const ( Other Kind = iota // Unclassified error -- does not appear in error strings Bug // Error is known to be a result of our bug Invalid // Invalid operation Permission // Permission denied IO // I/O error Exist // Item already exists NotExist // Item does not exist Encoding // Invalid encoding Crypto // Encryption or decryption error Locked // Wallet is locked Passphrase // Invalid passphrase Seed // Invalid seed WatchingOnly // Missing private keys InsufficientBalance // Insufficient balance to create transaction (perhaps due to UTXO selection requirements) ScriptFailure // Transaction scripts do not execute (usually due to missing sigs) Policy // Transaction rejected by wallet policy Consensus // Consensus violation DoubleSpend // Transaction is a double spend Protocol // Protocol violation NoPeers // Decred network is unreachable due to lack of peers or dcrd RPC connections Deployment // Inactive consensus deployment )
Error kinds.
func (Kind) As ¶
As implements the interface to work with the standard library's errors.As. If k is Other, this always returns false and target is not assigned. If target points to an *Error (i.e. target has type **Error), target is assigned an *Error using k as its Kind. If target points to a Kind, target is assigned the kind and As returns true. Else, target is not assinged and As returns false.