errors

package
v0.13.0 Latest Latest
Warning

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

Go to latest
Published: Jun 10, 2026 License: MIT Imports: 1 Imported by: 0

Documentation

Overview

Package errors provides helpers extending the standard errors package.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func AsAny

func AsAny(err error, targets ...any) bool

AsAny reports whether err matches any of the targets via errors.As.

Example
package main

import (
	"fmt"
	"io/fs"
	"os"
	"strconv"

	pkgerrors "github.com/foomo/go/errors"
)

func main() {
	var (
		pathErr *fs.PathError
		numErr  *strconv.NumError
	)

	_, err := os.Open("/nonexistent/path/for/example")
	fmt.Println(pkgerrors.AsAny(err, &numErr, &pathErr))
}
Output:
true

func AsAnyType

func AsAnyType(err error, targets ...any) bool

AsAnyType reports whether err matches any of the targets via errors.As.

Example
package main

import (
	"fmt"
	"io/fs"
	"os"
	"strconv"

	pkgerrors "github.com/foomo/go/errors"
)

func main() {
	_, err := os.Open("/nonexistent/path/for/example")
	fmt.Println(pkgerrors.AsAnyType(err, &fs.PathError{}, &strconv.NumError{}))
}
Output:
true

func IsAny

func IsAny(err error, targets ...error) bool

IsAny reports whether err matches any of the targets via errors.Is.

Example
package main

import (
	"context"
	"fmt"
	"io"

	pkgerrors "github.com/foomo/go/errors"
)

func main() {
	err := fmt.Errorf("wrapped: %w", io.EOF)
	fmt.Println(pkgerrors.IsAny(err, context.Canceled, io.EOF))
}
Output:
true

Types

This section is empty.

Jump to

Keyboard shortcuts

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