errors

package module
v0.0.0-...-9f787ce Latest Latest
Warning

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

Go to latest
Published: Dec 3, 2018 License: MIT Imports: 2 Imported by: 194

README

errors

This repository has moved to GitLab.

Documentation

Overview

Package errors is an extension of and drop in replacement for the standard library errors package. Multiple errors can be composed into a single error, and single errors can be extended with new errors or with context. You can also check whether any of the extensions or compositions contains a certain error, allowing for more flexible error handling for complex processes.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddContext

func AddContext(err error, context string) error

AddContext will add a string context to an error if the error is not nil. If the error is nil, then nil will be returned regardless of the context.

func Compose

func Compose(errs ...error) error

Compose will compose all errors together into a single error, remembering each component error so that they can be checked for matches later using the `Contains` function.

Any `nil` input errors will be ignored. If all input errors are `nil`, then `nil` will be returned.

func Contains

func Contains(base, cmp error) bool

Contains will check whether the base error contains the cmp error. If the base err is a Error, then it will check whether there is a match on any of the underlying errors.

func Extend

func Extend(err, extension error) error

Extend will extend the first error with the second error, remembering each component error so that they can be checked for matches later using the `Contains` function.

Any `nil` input will be ignored. If both inputs are `nil, then `nil` will be returned.

func IsOSNotExist

func IsOSNotExist(err error) bool

IsOSNotExist returns true if any of the errors in the underlying composition return true for os.IsNotExist.

func New

func New(s string) error

New is a passthrough to the stdlib errors package, allowing NebulousLabs/errors to be a drop in replacement for the standard library errors package.

Types

type Error

type Error struct {
	ErrSet []error
}

Error satisfies the error interface, and additionally keeps track of all extensions and compositions that have happened to the underlying errors.

func (Error) Error

func (r Error) Error() string

Error returns the composed error string of the Error, clustering errors by their composition and extension.

Jump to

Keyboard shortcuts

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