errorz

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Mar 23, 2021 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrMissingTransactions should be raised by an IsValidFunc if a proposal may
	// not be verified due to missing transactions.
	ErrMissingTransactions = errors.New("unable to verify: missing transactions")
	ErrBadResponse         = errors.New("bad response from p2p request to remote peer")
	ErrClosing             = errors.New("shutting down, halt actions")
	ErrCorrupt             = errors.New("something went wrong that requires shutdown")
)
View Source
var As = errors.As

As is shadowed export of errors.As

View Source
var Is = errors.Is

Is is shadowed export of errors.Is

Functions

func ErrMadNetType

func ErrMadNetType() **errMadNet

ErrMadNetType is a function for use in As IE As(<something>, ErrMadNetType())

Types

type ErrInvalid

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

func (*ErrInvalid) Error

func (e *ErrInvalid) Error() string

func (ErrInvalid) New

func (e ErrInvalid) New(msg string) *ErrInvalid

type ErrMadNet

type ErrMadNet interface {
	// Error interface method
	Error() string
	String() string
	// Unwrap for go>=1.13 unwrapping logic - IE: errors.Is and errors.As
	Unwrap() error
	// Trace returns a sorted list of called line numbers with context for
	// error tracing. Trace will only return data if WithTrace has been called
	// at some point in the stack. Otherwise it will return an empty list.
	Trace() []string
	// HasTrace returns true if any child error or the current error has a
	// trace enabled.
	HasTrace() bool
	// TraceStart returns the depth at which the trace begins in the error stack.
	// The max trace depth is 7. After seven trace entries have been added to the
	// trace stack, higher errors will simply proxy the trace of lower errors back
	// to the caller. The depth is measured as the number of times wrap is called
	// after the first time WithTrace() is called. This limit is to prevent
	// excessive abuse of CPU and memory for stack traces that may be discarded
	// by the caller.
	TraceStart() int
	// Depth returns the error stack depth.
	Depth() int
	// WithTrace enables tracing for the current error stack.
	WithTrace() ErrMadNet
	// WithContext allows a format string and a set of args to be passed for
	// string formatting. These values will be printed after the error message
	// for the bottom of the stack and beside the trace for elements above the
	// root of the stack.
	WithContext(fstring string, ctx ...interface{}) ErrMadNet
}

ErrMadNet is the custom error type used for MadNet. This error class acts as a normal error from go<1.13 and also creates the necessary logic for handling go>=1.13 error handling. Base Use Example:

func foo() (int, error) {
  aInt, err := bar()
  if err != nil {
    return errorz.Wrap(err)
  }
}

Extra features: This error type allows a traces of up to depth seven to be generated by wrapping at each layer of the call stack. Example:

func foo() (int, error) {
  aInt, err := bar()
  if err != nil {
    return errorz.Wrap(err).WithTrace()
  }
}

_, err := foo()
fmt.Printf("%s", strings.Join(foo, "\n"))

Result:
/some/package/path/to/file.go:line#

Where line number will be equal to the line
`return errorz.Wrap(err).WithTrace()`

This error class also allows a set of context variables to be attached to the error through WithContext() These context variable will print to the right of the traceback and after the error string for the root error.

func New

func New(e string) ErrMadNet

New creates a new MadNetError from a string

func Newf

func Newf(fmtString string, args interface{}) ErrMadNet

Newf creates a new MadNetError with string formatting

func Wrap

func Wrap(e error) ErrMadNet

Wrap an existing error and return a MadNetError

type ErrStale

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

func (*ErrStale) Error

func (e *ErrStale) Error() string

func (ErrStale) New

func (e ErrStale) New(msg string) *ErrStale

Jump to

Keyboard shortcuts

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