xdefer

package module
v0.0.0-...-6f3b6e4 Latest Latest
Warning

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

Go to latest
Published: Oct 17, 2022 License: BSD-3-Clause Imports: 3 Imported by: 1

README

xdefer

Package xdefer implements an extremely useful function, Errorf, to annotate all errors returned from a function transparently.

Install

go get oss.terrastruct.com/xdefer

Usage

Your code without xdefer:

func MyFunc() (err error) {
  err := doA()
  if err != nil {
    return fmt.Errorf("failed at MyFunc: %w", err)
  }
  err = doB()
  if err != nil {
    return fmt.Errorf("failed at MyFunc: %w", err)
  }
  ...
}

Your code with xdefer:

func MyFunc() (err error) {
  defer xdefer.Errorf(&err, "failed at MyFunc")

  err := doA()
  if err != nil {
    return err
  }
  err = doB()
  if err != nil {
    return err
  }
}

Documentation

Overview

Package xdefer implements an extremely useful function, Errorf, to annotate all errors returned from a function transparently.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Errorf

func Errorf(err *error, s string, v ...interface{})

Errorf makes it easy to defer annotate an error for all return paths in a function. See the tests for how it's used.

Pass s == "" to only annotate the location of the return.

Types

This section is empty.

Jump to

Keyboard shortcuts

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