runutil

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: May 28, 2024 License: Apache-2.0 Imports: 1 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CaptureError

func CaptureError(err *error, f func() error)

CaptureError runs f and optionally adds the returned error to the given error. This is supposed to be used for handling errors in defer statements. The first argument should point to an error return parameter. Often, errors are discarded like this, which is error-prone as closing an open file might be necessary to flush the written contents:

var f *os.File
// ...
defer f.Close()

Instead, use CaptureError to handle the returned error:

 func foo() (err error) {
	   var f *os.File
	   // ...
	   defer runutil.CaptureError(&err, f.Close)
	   // ...
	 }

If the error return parameter is non-nil and Close errors, CaptureError sets the error return parameter to a multierror capturing both errors. If only one error occurs, the return parameter is set to exactly that error.

Types

This section is empty.

Jump to

Keyboard shortcuts

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