errors

package module
v0.0.0-...-f2d483e Latest Latest
Warning

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

Go to latest
Published: Oct 13, 2020 License: MIT Imports: 6 Imported by: 0

README

errors

Errors package compatible with https://github.com/pkg/errors with some sprinkles.

Actions Status GoDoc Report card

Adding context to an error

Adding fields to an error

Retrieve fields associated with an error

Retrieving the cause of an error

Unpack wrapped errors

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Cause

func Cause(err error) error

Cause returns the underlying cause of the error, if possible. An error value has a cause if it implements the following interface:

type causer interface {
       Cause() error
}

If the error does not implement Cause, the original error will be returned. If the error is nil, nil will be returned without further investigation.

func Errorf

func Errorf(format string, args ...interface{}) error

Errorf formats according to a format specifier and returns the string as a value that satisfies error. Errorf also records the stack trace at the point it was called.

func New

func New(message string) error

New returns an error with the supplied message. New also records the stack trace at the point it was called.

func Unpack

func Unpack(err error) []error

Unpack returns a slice of all the underlying errors, if possible. An error value has a cause if it implements the following interface:

type causer interface {
       Cause() error
}

If the error is nil, an empty slice will be returned.

func WithField

func WithField(err error, key string, value interface{}) error

WithField annotates err with the specified field. If err is nil, WithFields returns nil.

func WithFields

func WithFields(err error, fields Fields) error

WithFields annotates err with fields. If err is nil, WithFields returns nil.

func WithMessage

func WithMessage(err error, message string) error

WithMessage annotates err with a new message. If err is nil, WithMessage returns nil.

func WithMessagef

func WithMessagef(err error, format string, args ...interface{}) error

WithMessagef annotates err with the format specifier. If err is nil, WithMessagef returns nil.

func WithStack

func WithStack(err error) error

WithStack annotates err with a stack trace at the point WithStack was called. If err is nil, WithStack returns nil.

func Wrap

func Wrap(err error, message string) error

Wrap returns an error annotating err with a stack trace at the point Wrap is called, and the supplied message. If err is nil, Wrap returns nil.

func Wrapf

func Wrapf(err error, format string, args ...interface{}) error

Wrapf returns an error annotating err with a stack trace at the point Wrapf is called, and the format specifier. If err is nil, Wrapf returns nil.

Types

type Error

type Error string

Error is used to be able to declare const errors

func (Error) Error

func (e Error) Error() string

type Fields

type Fields map[string]interface{}

Fields is used to manipulate error fields.

func GetFields

func GetFields(err error) Fields

GetFields retrieve all the fields associated with an error stack. If the error is nil, an empty slice will be returned.

func (Fields) Fields

func (f Fields) Fields() log.Fields

Fields is used for compatibility with Apex Log WithFields method.

Jump to

Keyboard shortcuts

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