errorkitlite

package
v0.304.1 Latest Latest
Warning

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

Go to latest
Published: Sep 27, 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/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

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 added in v0.302.0

type Error string
const ErrNotImplemented Error = "ErrNotImplemented"

func (Error) Error added in v0.302.0

func (err Error) Error() string

func (Error) F added in v0.302.0

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 added in v0.302.0

type W struct {
	E Error
	W error
}

func (W) As added in v0.302.0

func (w W) As(target any) bool

func (W) Error added in v0.302.0

func (w W) Error() string

func (W) Is added in v0.302.0

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