errors

package module
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Sep 21, 2021 License: MIT Imports: 6 Imported by: 6

Documentation

Overview

Copied (and modified) from: github.com/pkg/errors@v0.9.1/stack.go

Index

Constants

This section is empty.

Variables

View Source
var (
	Panic = New(icPanic, "recovered panic")
)

Functions

func As

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

As finds the first error in err's chain that matches target, and if so, sets target to that error value and returns true. Otherwise, it returns false. See: https://golang.org/pkg/errors/#As

func Catch added in v0.2.0

func Catch(fn func()) (err error)

Catch potential panics that occur in a function call. Panics should never occur, therefore stack traces print regardless of build mode (release or debug).

func Cause

func Cause(err error) error

Cause of the error. This returns the very first error encoutered whether that was a new application error or an external error.

func Convert added in v0.2.0

func Convert(internalCode string, fromErr error, toErr error) error

Convert an existing error to a new error. Calls to As(), Is(), InternalCode(), Cause(), and Unwrap() will only refer to the new error. Original error used for formatting/printing only. This may be useful when a concrete error should be returned from a function to enable consumers

to detect this error with As() or Is().

func InternalCode added in v0.1.0

func InternalCode(err error) string

InternalCode of the first error created or converted. If err does not have an internal code then return empty string.

func Is

func Is(err, target error) bool

Is reports whether any error in err's chain matches target. See: https://golang.org/pkg/errors/#Is

func New

func New(internalCode string, format string, values ...interface{}) error

New error. This should be called when the application creates a brand new error. If an error has been received from an external function or is propogating an error, use Propagate().

func Propagate added in v0.2.0

func Propagate(internalCode string, err error) error

Propagate an existing error. The internalCode should be a unique code to allow developers to easily identify the source of an issue.

func Recover added in v0.2.0

func Recover(errPanic interface{}) error

func Unwrap

func Unwrap(err error) error

Unwrap returns the result of calling the Unwrap method on err, if err's type contains an Unwrap method returning error. Otherwise, Unwrap returns nil. See: https://golang.org/pkg/errors/#Unwrap

Types

type Frame added in v0.1.0

type Frame uintptr

Frame represents a program counter inside a stack frame. For historical reasons if Frame is interpreted as a uintptr its value represents the program counter + 1.

func (Frame) Format added in v0.1.0

func (f Frame) Format(s fmt.State, verb rune)

Format formats the frame according to the fmt.Formatter interface.

%s    source file
%d    source line
%v    equivalent to %s:%d

Format accepts flags that alter the printing of some verbs, as follows:

%+s   function name and path of source file relative to the compile time
      GOPATH separated by \n\t (<funcname>\n\t<path>)
%+v   equivalent to %+s:%d

Jump to

Keyboard shortcuts

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