errors

package
v0.5.1 Latest Latest
Warning

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

Go to latest
Published: Sep 18, 2021 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package errors defines error handling used by shed.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Is

func Is(err, target error) bool

Is is errors.Is from the standard library.

func New

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

New creates an error value from its arguments. There must be at least one argument or New panics. The type of each argument determines what field of Error it is assigned to. If an argument has an invalid type New panics.

func Str

func Str(s string) error

Str is a wrapper over errors.New from the standard library.

Types

type Error

type Error struct {
	// Kind is the category of error.
	Kind Kind
	// Reason is a human-readable message containing
	// the details of the error.
	Reason string
	// Op is the operation being performed, usually the
	// name of a function or method being invoked.
	Op Op
	// Err is the underlying error that triggered this one.
	// If no underlying error occurred, it will be nil.
	Err error
}

Error represents a shed error.

func Root

func Root(err error) *Error

Root finds the root error in the error chain that is of type *Error. It will keep unwrapping errors that have a non-nil Err field. If err is not of type *Error or does not wrap an *Error, nil will be returned.

func (*Error) Error

func (e *Error) Error() string

func (*Error) Format

func (e *Error) Format(s fmt.State, verb rune)

func (*Error) Unwrap

func (e *Error) Unwrap() error

type Kind

type Kind uint8

Kind identifies the category of an error.

Kind is used to group errors based on how they can be actioned.

const (
	Unspecified  Kind = iota // Error that does not fall into any category.
	Invalid                  // Invalid operation on an item.
	NotInstalled             // A tool needs to be installed for the operation to work.
	BadState                 // Shed is in a bad state, but it can be fixed.
	Internal                 // Internal error or inconsistency.
	IO                       // An OS level I/O error.
	Go                       // An error returned from the go command.
)

func (Kind) String

func (k Kind) String() string

type List

type List []error

List contains multiple errors that occurred while performing an operation.

func (List) Error

func (e List) Error() string

type Op

type Op string

Op describes an operation, usually a function or method name such as "Shed.Get".

Jump to

Keyboard shortcuts

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