errors

package
v0.14.1 Latest Latest
Warning

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

Go to latest
Published: Jul 29, 2026 License: MIT Imports: 2 Imported by: 2 modules, 2 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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 the concrete type of any of the targets via errors.As. Each target must be a pointer to the error type to match (e.g. &fs.PathError{}); unlike AsAny, the caller need not declare target variables and the matched value is discarded. nil targets are skipped.

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