errorkitlite

package
v0.307.0 Latest Latest
Warning

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

Go to latest
Published: Oct 28, 2025 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func As

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

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/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

func Finish(returnErr *error, blk func() error)

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

func Merge(errs ...error) error

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 MergeErrFunc(errFuncs ...ErrFunc) func() error

func NullErrFunc

func NullErrFunc() error

func Recover

func Recover(returnErr *error)

Recover will attempt a recover, and if recovery yields a value, it sets it as an 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

type Error string
const ErrNotImplemented Error = "ErrNotImplemented"

func (Error) Error

func (err Error) Error() string

func (Error) F

func (err Error) F(format string, a ...any) error

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

type W

type W struct {
	E Error
	W error
}

func (W) As

func (w W) As(target any) bool

func (W) Error

func (w W) Error() string

func (W) Is

func (w W) Is(target error) bool

Jump to

Keyboard shortcuts

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