errutil

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Dec 16, 2024 License: BSD-3-Clause Imports: 1 Imported by: 0

Documentation

Overview

Package errutil provides utilities for easily annotating Go errors.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Annotatef

func Annotatef(err *error, format string, a ...any)

Annotatef annotates non-nil error with the given message.

It's designed to be used in a defer, for example:

func g(arg string) (err error) {
   defer Annotate(&err, fmt.Sprintf("g(%s)")
   return errors.New("my error")
}

Calling g("hello") will result in error message:

g(hello): my error

Annotate allows using the above short form instead of the long form:

func g(arg string) (err error) {
   defer func() {
     if err != nil {
       err = fmt.Errorf("g(%s): %v", arg, err)
      }
   }()
   return errors.New("my error")
}

Types

This section is empty.

Jump to

Keyboard shortcuts

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