errors

package
v0.0.0-...-db8c6ed Latest Latest
Warning

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

Go to latest
Published: Feb 12, 2021 License: MIT Imports: 1 Imported by: 10

Documentation

Overview

Package errors provides extra functionalities to that of Go's stdlib errors package.

TODO: fields. e.g., errors.Msg("error message", errors.Str("name", name), errors.Err(err))

or errors.With().Str("name", name).Err(err).Msg("error message")
or errors.With().StrErr("name", nameErr).Msg("error message")

(sounds like structured logging? exactly!)

Index

Constants

This section is empty.

Variables

View Source
var (
	As     = errors.As
	Is     = errors.Is
	New    = errors.New // Prefer Msg instead of New as it has better semantic
	Msg    = errors.New
	Unwrap = errors.Unwrap
)

Wraps Go's errors

View Source
var ErrUnimplemented = Msg("unimplemented")

ErrUnimplemented is used to declare that a functionality, or part of it, has not been implemented. This could be well mapped to some protocols' status code, e.g., HTTP's 501 and gRPC's 12 .

Functions

func Arg

func Arg(argName string, err error, fields ...EntityError) error

func ArgMsg

func ArgMsg(argName, errMsg string, fields ...EntityError) error

func ArgWrap

func ArgWrap(argName, contextMessage string, err error, fields ...EntityError) error

func IsCallError

func IsCallError(e error) bool

func Wrap

func Wrap(contextMessage string, causeErr error) error

Wrap creates a new error by providing context message to another error. It's recommended for the message to describe what the program did which caused the error.

err := fetchData(...)
if err != nil { return errors.Wrap("fetching data", err) }

Types

type ArgumentError

type ArgumentError interface {
	ArgumentName() string
}

type CallError

type CallError interface {
	error
	CallError()
}

type EntityError

type EntityError interface {
	error
	EntityIdentifier() string
}

func Ent

func Ent(entityIdentifier string, err error) EntityError

Ent creates an instance of error which conforms EntityError. It takes entityIdentifier which could be the name, key or URL of an entity. The entityIdentifier should describe the 'what' while err describes the 'why'.

// Describes that the file ".config.yaml" does not exist.
errors.Ent("./config.yaml", os.ErrNotExist)

// Describes that the site "https://example.com" is unreachable.
errors.Ent("https://example.com/", errors.Msg("unreachable"))

func EntMsg

func EntMsg(entityIdentifier string, errMsg string) EntityError

EntMsg creates an instance of error from an entitity identifier and the error message which describes why the entity is considered error.

type Unwrappable

type Unwrappable interface {
	error
	Unwrap() error
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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