errext

package
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: Oct 25, 2023 License: Apache-2.0 Imports: 1 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func As

func As[T error](err error) (T, bool)

As is a variant of errors.As() that leverages generics to present a nicer interface.

//this code:
var perr os.PathError
if errors.As(err, &perr) {
	handle(perr)
}
//can be rewritten as:
if perr, ok := errext.As[os.PathError](err); ok {
	handle(perr)
}

This is sometimes more verbose (like in this example), but allows to scope the specific error variable to the condition's then-branch, and also looks more idiomatic to developers already familiar with type casts.

Types

This section is empty.

Jump to

Keyboard shortcuts

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