Documentation ¶
Overview ¶
Package errext contains convenience functions for handling and propagating errors.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func As ¶
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 ¶
type ErrorSet ¶
type ErrorSet []error
ErrorSet replaces the "error" return value in functions that can return multiple errors. It provides convenience functions for easily adding errors to the set.
func (ErrorSet) Join ¶
Join joins the messages of all errors in this set using the provided separator. If the set is empty, an empty string is returned.
func (ErrorSet) LogFatalIfError ¶
func (errs ErrorSet) LogFatalIfError()
LogFatalIfError reports all errors in this set on level FATAL, thus dying if there are any errors.