checkpoint

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Mar 3, 2021 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package checkpoint provides a way to decorate errors by some additional caller information which results in something similar to a stacktrace. Each error added to a checkpoint can be checked by errors.Is and retrieved by errors.As.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func From

func From(err error) error

From just wraps an error by a new checkpoint which adds some caller information to the error. It returns nil, if err == nil.

func Wrap

func Wrap(prev, err error) error

Wrap adds a checkpoint with some caller information from an error and accepts also another error which can further describe the checkpoint. Returns nil if prev == nil. If err is nil, it still creates a checkpoint. This allows for example to predefine some errors and use them later:

var(
		ErrSomethingSpecialWentWrong = errors.New("a very bad error")
)
func someFunction() error {
	err := somethingOtherThatThrowsErrors()
	return checkpoint.Wrap(err, ErrSomethingSpecialWentWrong)
}

err := someFunction()

If used that way, you can still check with errors.Is() for the ErrSomethingSpecialWentWrong

if errors.Is(err, ErrSomethingSpecialWentWrong) {
	fmt.Println("The special error was thrown")
} else {
	fmt.Println(err)
}

but also for the error returned by somethingOtherThatThrowsErrors() (if you know what error it is). If the error in this example is nil, no checkpoint gets created.

Types

This section is empty.

Jump to

Keyboard shortcuts

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