Documentation ¶
Overview ¶
Package errutil extends go errors with various helpers.
Index ¶
- Variables
- func Append(err error, errs ...error) error
- func Fmt(format string, parts ...any) error
- func New(parts ...any) (err error)
- func Prefix(err error, s string) error
- func PrintErrors(err error, w func(s string))
- func Sprint(parts ...any) string
- type Error
- type Func
- type NoPanic
- type NoPanicError
Constants ¶
This section is empty.
Variables ¶
var Fprintf = fmt.Fprintf
Fprintf acts like its package fmt counterpart. See errutil.Sprintf for notses.
var Panic = false
Panic when true triggers on any new errutil error... unless it implements the NoPanic interface
var Sprintf = fmt.Sprintf
Sprintf acts like its package fmt counterpart. It removes a direct dependency on fmt to make usages other uses of fmt easier to find. It may eventually change to use a lighterweight formatting, ex. maybe using pkg/internal/reflectlite ( for %T handling. )
Functions ¶
func New ¶
New captures the passed arguments to build an error. Wraps the last element if it's an error. The returned error delays evaluating the parts until `Error() string`, Relies on the presumption that, in an error state, the rest of the program wont be altering pending values anyway. If that's not true, then Sprint or Sprintf are better options.
func PrintErrors ¶
PrintErrors is a utility function that prints a list of errors to w, one error per line, if the err parameter is a MultiError. Otherwise it prints the err string. w is not a writer b/c log.Writer() doesnt generate log headers automatically and note log.Println and fmt.Println have different signatures, so yay. we use the simplest form possible here.
Types ¶
type Error ¶
type Error string
Error type which uses a single string as an error. Can also be used to create error constants. https://dave.cheney.net/2016/04/07/constant-errors ex. const MyError = errutil.Error("github.com/a/package/MyError")
type Func ¶
type Func func() string
Func delays error string generation until the error string gets accessed. It does this by implementing the go Error() interface for parameterless functions. For example: funError:= errutil.Func(func() string { return "fun" })
type NoPanic ¶
type NoPanic interface{ NoPanic() }
NoPanic - custom errors can implement this to stop errutil from panicing. useful on occasion for provisional error types
type NoPanicError ¶
type NoPanicError string
Error type which uses a single string as an error and which implements the generic NoPanic interface.
func (NoPanicError) Error ¶
func (e NoPanicError) Error() string
func (NoPanicError) Is ¶
func (e NoPanicError) Is(target error) bool
func (NoPanicError) NoPanic ¶
func (e NoPanicError) NoPanic()