errors

package
v0.0.0-...-9e8562e Latest Latest
Warning

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

Go to latest
Published: Nov 1, 2019 License: ISC Imports: 4 Imported by: 1

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

Constants

This section is empty.

Variables

View Source
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 Cause

func Cause(err error) error

Cause returns the most deeply-nested error from an error chain. Cause never returns nil unless the argument is nil.

func E

func E(args ...interface{}) error

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 Errorf

func Errorf(format string, args ...interface{}) error

Errorf creates a simple error from a format string and arguments. Errorf is identical to "fmt".Errorf from the standard library.

func Is

func Is(kind Kind, err error) bool

Is returns whether err is of type *Error and has a matching kind in err or any nested errors. Does not match against the Other kind.

func Match

func Match(err1, err2 error) bool

Match compares two Errors, returning true if every non-zero field of err1 is equal to the same field in err2. Nested errors in err1 are similarly compared to any nested error of err2.

func MatchAll

func MatchAll(needle, haystack error) bool

MatchAll performs Match on needle using haystack and every nested error of haystack.

func New

func New(text string) error

New creates a simple error from a string. New is identical to "errors".New from the standard library.

func Stacks

func Stacks(err error) [][]byte

Stacks extracts all stacktraces from err, sorted from top-most to bottom-most error.

func WithStack

func WithStack(args ...interface{}) error

WithStack is identical to E but includes a stacktrace with the error. Stack traces do not appear in formatted error strings and are not compared when matching errors. Stack traces are extracted from errors using Stacks.

Types

type Error

type Error struct {
	Op   Op
	Kind Kind
	Err  error
	// contains filtered or unexported fields
}

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) Error

func (e *Error) Error() string

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                         // Utopia network is unreachable due to lack of peers or ucd RPC connections
	Deployment                      // Inactive consensus deployment
)

Error kinds.

func (Kind) String

func (k Kind) String() string

type Op

type Op string

Op describes the operation, method, or RPC in which an error condition was raised.

func Opf

func Opf(format string, a ...interface{}) Op

Opf returns a formatted Op.

Jump to

Keyboard shortcuts

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