error

package
v1.7.1 Latest Latest
Warning

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

Go to latest
Published: Sep 16, 2021 License: Apache-2.0 Imports: 5 Imported by: 56

Documentation

Overview

The error package provides practical wrap/unwrap features. The Wrap() function will capture caller provided and the captured stack. The stack is captured only on the first call to Wrap(). Subsequent calls to Wrap() will augment the description and key/value pair context only. Wrap() may safely be called with `nil`. The Unwrap() function will provide the original wrapped error. The New() function will create a new, wrapped error.

Example:

// // Simple Wrap/Unwrap. a := errors.New("No route to host"). b := Wrap(a) c = Unwrap(b) // a == c

// // Wrap with context. url := "http://host/..." d := e1.Wrap(

a, "Web request failed."
"url", url)

d.Error() // "Web request failed. caused by: 'No route to host'" d.Context() // []string{"url", "http://host/..."}

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func New

func New(m string, kvpair ...interface{}) error

Create a new wrapped error.

func Unwrap added in v0.2.6

func Unwrap(err error) (out error)

Unwrap an error. Returns: the original error when not wrapped.

func Wrap

func Wrap(err error, kvpair ...interface{}) error

Wrap an error. Returns `err` when err is `nil` or *Error.

Types

type Error

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

Error. Wraps a root cause error and captures the stack.

func (Error) Context added in v0.2.9

func (e Error) Context() []interface{}

Get `context` key/value pairs.

func (Error) Error

func (e Error) Error() string

Error description.

func (Error) Stack

func (e Error) Stack() string

Error stack trace. Format:

package.Function()
  file:line
package.Function()
  file:line
...

func (Error) Unwrap

func (e Error) Unwrap() error

Unwrap the error.

Jump to

Keyboard shortcuts

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