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 ¶
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 ¶
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 ¶
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.
Click to show internal directories.
Click to hide internal directories.