Documentation ¶
Overview ¶
The Tideland Go Library errors package 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
- func All(err error) []error
- func Annotate(err error, code int, msgs Messages, args ...interface{}) error
- func Annotated(err error) error
- func Collect(errs ...error) error
- func DeprecatedError(feature string) error
- func DoAll(err error, f func(error))
- func IsDeprecatedError(err error) bool
- func IsError(err error, code int) bool
- func IsInvalidTypeError(err error) bool
- func IsNotYetImplementedError(err error) bool
- func Location(err error) (string, string, int, error)
- func New(code int, msgs Messages, args ...interface{}) error
- func NotYetImplementedError(feature string) error
- func PackageVersion() version.Version
- func Stack(err error) []error
- func Valid(err error) bool
- type Messages
Constants ¶
const ( ErrInvalidErrorType = iota + 1 ErrNotYetImplemented ErrDeprecated )
Variables ¶
This section is empty.
Functions ¶
func Annotated ¶
Annotated returns the possibly annotated error. In case of a different error an invalid type error is returned.
func DeprecatedError ¶
DeprecatedError returns the common error for a deprecated feature.
func DoAll ¶
DoAll iterates the passed function over all stacked or collected errors or simply the one that's passed.
func IsDeprecatedError ¶
IsDeprecatedError checks if an error signals deprecated feature.
func IsInvalidTypeError ¶
IsInvalidTypeError checks if an error signals an invalid type in case of testing for an annotated error.
func IsNotYetImplementedError ¶
IsNotYetImplementedError checks if an error signals a not yet implemented feature.
func Location ¶
Location returns the package and the file name as well as the line number of the error.
func NotYetImplementedError ¶
NotYetImplementedError returns the common error for a not yet implemented feature.
func PackageVersion ¶
PackageVersion returns the version of the version package.