errors

package
v7.3.0 Latest Latest
Warning

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

Go to latest
Published: Feb 19, 2021 License: MIT Imports: 7 Imported by: 1

README

errors

Package errors implements functions to manipulate errors.

Errors created are taggable and wrappable.

errWithTags := errors.New("an error with tags").
    Tag("a", 42).
    Tag("b", 21)

errWithWrap := errors.New("error").
    Tag("a", 42).
    Wrap(errors.New("wrapped error"))

The package mirrors https:golang.org/pkg/errors package.

Documentation

Overview

Package errors implements functions to manipulate errors.

Errors created are taggable and wrappable.

  errWithTags := errors.New("an error with tags").
      Tag("a", 42).
	     Tag("b", 21)

  errWithWrap := errors.New("error").
      Tag("a", 42).
	     Wrap(errors.New("wrapped error"))

The package mirrors https://golang.org/pkg/errors package.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func As

func As(err error, target interface{}) bool

As is documented at https://golang.org/pkg/errors/#As.

func Is

func Is(err, target error) bool

Is is documented at https://golang.org/pkg/errors/#Is.

func Tag

func Tag(err error, k string) (string, bool)

Tag retrieves the value of the tag named by the key. If the tag exists, its value (which may be empty) is returned and the boolean is true. Otherwise the returned value will be empty and the boolean will be false.

func Unwrap

func Unwrap(err error) error

Unwrap is documented at https://golang.org/pkg/errors/#Unwrap.

Types

type Error

type Error struct {
	// contains filtered or unexported fields
}

Error is an error implementation that supports tagging and wrapping.

func New

func New(v string) Error

New returns an error with the given description that can be tagged.

func Newf

func Newf(format string, v ...interface{}) Error

Newf returns an error with the given formatted description that can be tagged.

func (Error) Error

func (e Error) Error() string

func (Error) Is

func (e Error) Is(target error) bool

Is reports if the target matches the error or its wrapped values.

func (Error) Lookup

func (e Error) Lookup(tag string) (string, bool)

Lookup retrieves the value of the tag named by the key. If the tag exists, its value (which may be empty) is returned and the boolean is true. Otherwise the returned value will be empty and the boolean will be false.

func (Error) Tag

func (e Error) Tag(k string, v interface{}) Error

Tag sets the named tag with the given value.

func (Error) Unwrap

func (e Error) Unwrap() error

Unwrap unwraps the given error.

func (Error) Wrap

func (e Error) Wrap(err error) Error

Wrap wraps the given error. Nil errors are ingnored.

Jump to

Keyboard shortcuts

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