errors

package
v4.24.2+incompatible Latest Latest
Warning

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

Go to latest
Published: Sep 9, 2017 License: BSD-3-Clause Imports: 4 Imported by: 14

Documentation

Overview

Package errors of the Tideland Go Library allows to create more detailed errors than with errors.New() or fmt.Errorf(). When trying to differentiate between different errors or to carry helpful payload own types are needed.

The errors package allows to easily created formatted errors with New() like with the fmt.Errorf() function, but also with an error code. Additionlly a Messages instance has to be passed to map the error code to their according messages.

If an error alreay exists use Annotate(). This way the original error will be stored and can be retrieved with Annotated(). Also its error message will be appended to the created error separated by a colon.

All errors additionally contain their package, filename and line number. These information can be retrieved using Location(). In case of a chain of annotated errors those can be retrieved as a slice of errors with Stack().

Index

Constants

View Source
const (
	ErrInvalidErrorType = iota + 1
	ErrNotYetImplemented
	ErrDeprecated
)

Error codes of the errors package.

Variables

This section is empty.

Functions

func All

func All(err error) []error

All returns a slice of errors in case of collected errors.

func Annotate

func Annotate(err error, code int, msgs Messages, args ...interface{}) error

Annotate creates an error wrapping another one together with a a code.

func Annotated

func Annotated(err error) error

Annotated returns the possibly annotated error. In case of a different error an invalid type error is returned.

func Collect

func Collect(errs ...error) error

Collect collects multiple errors into one.

func DeprecatedError

func DeprecatedError(feature string) error

DeprecatedError returns the common error for a deprecated feature.

func DoAll

func DoAll(err error, f func(error))

DoAll iterates the passed function over all stacked or collected errors or simply the one that's passed.

func IsDeprecatedError

func IsDeprecatedError(err error) bool

IsDeprecatedError checks if an error signals deprecated feature.

func IsError

func IsError(err error, code int) bool

IsError checks if an error is one created by this package and has the passed code

func IsInvalidTypeError

func IsInvalidTypeError(err error) bool

IsInvalidTypeError checks if an error signals an invalid type in case of testing for an annotated error.

func IsNotYetImplementedError

func IsNotYetImplementedError(err error) bool

IsNotYetImplementedError checks if an error signals a not yet implemented feature.

func Location

func Location(err error) (string, string, int, error)

Location returns the package and the file name as well as the line number of the error.

func New

func New(code int, msgs Messages, args ...interface{}) error

New creates an error with the given code.

func NotYetImplementedError

func NotYetImplementedError(feature string) error

NotYetImplementedError returns the common error for a not yet implemented feature.

func Stack

func Stack(err error) []error

Stack returns a slice of errors down to the first non-errors error in case of annotated errors.

func Valid

func Valid(err error) bool

Valid returns true if it is a valid error generated by this package.

Types

type Messages

type Messages map[int]string

Messages contains the message strings for the the error codes.

func (Messages) Format

func (m Messages) Format(code int, args ...interface{}) string

Format returns the formatted error message for code with the given arguments.

Jump to

Keyboard shortcuts

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