errors

package
v1.64.1 Latest Latest
Warning

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

Go to latest
Published: May 8, 2020 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package errors is a custom library to annotate errors.

Based on https://godoc.org/github.com/samsarahq/go/oops and adapted to our function names and needs.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func As added in v1.54.0

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.

func Cause

func Cause(err error) error

Cause extracts the cause error of an altipla error. If err is not an altipla error, err itself is returned.

You can use Cause to check if an error is an expected error. For example, if you know than EOF error is fine, you can handle it with Cause.

func Details

func Details(err error) string

func Errorf

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

Errorf creates a new error with a reason and a stacktrace.

Use Errorf in places where you would otherwise return an error using fmt.Errorf or errors.New.

Note that the result of Errorf includes a stacktrace. This means that Errorf is not suitable for storing in global variables. For such errors, keep using errors.New.

func Frames

func Frames(err error) [][]Frame

Frames extracts all frames from an altipla error. If err is not an altipla error, nil is returned.

func Is added in v1.22.0

func Is(err, target error) bool

Is reports whether err or its cause matches target.

func LogFields added in v1.11.1

func LogFields(err error) log.Fields

func New

func New(err string) error

New creates a new error without stacktrace.

func Recover

func Recover(p interface{}) error

Recover recovers from a panic in a defer. If there is no panic, Recover() returns nil. To use, call error.Recover(recover()) and compare the result to nil.

func Stack added in v1.12.1

func Stack(err error) string

func Trace

func Trace(err error) error

Trace annotates an error with a stacktrace.

Use Trace in places where you would otherwise return an error directly. If the error passed to Trace is nil, Trace will also return nil. This makes it safe to use in one-line return statements.

To check if a wrapped error is a specific error, such as io.EOF, you can extract the error passed in to Trace using Cause.

func Wrapf

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

Wrapf annotates an error with a reason and a stacktrace. If err is nil, Wrapf returns nil.

Use Wrapf in places where you would otherwise return an error directly. If the error passed to Wrapf is nil, Wrapf will also return nil. This makes it safe to use in one-line return statements.

To check if a wrapped error is a specific error, such as io.EOF, you can extract the error passed in to Wrapf using Cause.

Types

type Frame

type Frame struct {
	File     string
	Function string
	Line     int
	Reason   string
}

A Frame represents a Frame in an altipla callstack. The Reason is the manual annotation passed to altipla.Wrapf.

Jump to

Keyboard shortcuts

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