Documentation
¶
Index ¶
- func As[T error](err error) (T, bool)
- func Finish(returnErr *error, blk func() error)
- func FinishOnError(returnErr *error, blk func())
- func Merge(errs ...error) error
- func MergeErrFunc(errFuncs ...ErrFunc) func() error
- func NullErrFunc() error
- func Recover(returnErr *error)
- type ErrFunc
- type Error
- type MultiError
- type W
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func As ¶
As function serves as a shorthand to enable one-liner error handling with errors.As. It's meant to be used within an if statement, much like Lookup functions such as os.LookupEnv.
Example ¶
package main import ( "fmt" "go.llib.dev/frameless/pkg/internal/errorkitlite" ) type MyError struct { Msg string } func (err MyError) Error() string { return err.Msg } func main() { var err error // some error to be checked if err, ok := errorkitlite.As[MyError](err); ok { fmt.Println(err.Msg) } }
func Finish ¶
Finish is a helper function that can be used from a deferred context.
Usage:
defer errorkit.Finish(&returnError, rows.Close)
func FinishOnError ¶
func FinishOnError(returnErr *error, blk func())
FinishOnError is a helper function that can be used from a deferred context. It runs the block conditionally, when the return error, which was assigned by the `return` keyword is not nil.
Usage:
defer errorkit.FinishOnError(&returnError, func() { rollback(ctx) })
func Merge ¶
Merge will combine all given non nil error values into a single error value. If no valid error is given, nil is returned. If only a single non nil error value is given, the error value is returned.
func MergeErrFunc ¶
func NullErrFunc ¶
func NullErrFunc() error
Types ¶
type ErrFunc ¶
type ErrFunc = func() error
ErrFunc is a function that checks whether a stateful system currently has an error. For example context.Context#Err is an ErrFunc.
type Error ¶ added in v0.302.0
type Error string
const ErrNotImplemented Error = "ErrNotImplemented"
type MultiError ¶
type MultiError []error
func (MultiError) As ¶
func (errs MultiError) As(target any) bool
func (MultiError) Error ¶
func (errs MultiError) Error() string
func (MultiError) Is ¶
func (errs MultiError) Is(target error) bool