errval

package
v0.17.2 Latest Latest
Warning

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

Go to latest
Published: Aug 13, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package errval provides a way to add values to errors.

Example
err := errbase.New("error")
err = Wrap(err, "foo", "bar")
vals := Get(err)
fmt.Println(vals["foo"])
Output:
bar

Index

Examples

Constants

This section is empty.

Variables

View Source
var VerboseWriter atomicutil.Value[func(io.Writer, any)]

VerboseWriter writes the representation of a value in a verbose message.

It can be changed in order to customize how values are formatted.

By default it uses pretty.Write.

Functions

func All added in v0.13.0

func All(err error) iter.Seq2[string, any]

All returns a iter.Seq2 of values added to an error.

func Get

func Get(err error) map[string]any

Get returns the values added to an error.

func GetValue added in v0.16.1

func GetValue(err error, key string) (any, bool)

GetValue returns the first value added to an error for the given key.

It returns false if the key is not found.

Example
err := errbase.New("error")
err = Wrap(err, "foo", "bar")
val, ok := GetValue(err, "foo")
fmt.Println(ok, val)
Output:
true bar

func Wrap

func Wrap(err error, key string, val any) error

Wrap adds a value to an error.

The verbose message is "value <key> = <val>". The value is written using the VerboseWriter function.

Types

This section is empty.

Jump to

Keyboard shortcuts

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