error

package
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Feb 16, 2024 License: Apache-2.0 Imports: 4 Imported by: 37

Documentation

Overview

Package 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("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

New returns a new wrapped error.

func Unwrap

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 provides an error with context and stack.

func (Error) Context

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

Context returns the`context` key/value pairs.

func (Error) Error

func (e Error) Error() string

Error description.

func (Error) Stack

func (e Error) Stack() string

Stack returns the 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