errors

package module
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Apr 14, 2025 License: MIT Imports: 7 Imported by: 75

README

A simple error wrapping package for Go

CI Go Report Card Slack chat

This is a simple error wrapping package that automatically adds source locations to errors. It has the same API as github.com/pkg/errors but is much lighter weight.

If the envar "DEBUG=1" is true, any errors from this package that are printed will display <file>:<line> annotations at each wrapping location.

Documentation

Overview

Package errors is a simple error wrapping package that automatically adds source locations to errors. It has the same API as github.com/pkg/errors but is much lighter weight.

If the envar "DEBUG=1" is true, any errors from this package that are printed will display <file>:<line> annotations at each wrapping location.

Index

Constants

This section is empty.

Variables

View Source
var Debug = os.Getenv("DEBUG") != ""

Debug is set by the envar "$DEBUG" but may be overridden.

Functions

func As

func As(err error, target any) bool

As mirrors the stdlib errors.As function.

func Errorf

func Errorf(format string, args ...any) error

Errorf creates a new error using fmt.Sprintf().

func Innermost

func Innermost(err error) bool

Innermost returns true if err cannot be further unwrapped.

func Is

func Is(err, target error) bool

Is mirrors the stdlib errors.Is function.

func Join

func Join(errs ...error) error

Join returns an error that wraps the given errors. Any nil error values are discarded. Join returns nil if errs contains no non-nil values. The error formats as the concatenation of the strings obtained by calling the Error method of each element of errs, with a newline between each string.

func New

func New(message string) error

New creates a new error.

func Unwrap

func Unwrap(err error) error

Unwrap aliases the stdlib errors.Unwrap function.

func UnwrapAll

func UnwrapAll(err error) []error

UnwrapAll recursively unwraps all errors in err, including all intermediate errors.

func WithStack

func WithStack(err error) error

WithStack chains source location information to an error if "err" is not nil.

func Wrap

func Wrap(err error, message string) error

Wrap chains a new error to "err" if it is not nil.

func Wrapf

func Wrapf(err error, format string, args ...any) error

Wrapf chains a new fmt.Sprintf() formatted error to "err" if "err" is not nil.

Types

This section is empty.

Jump to

Keyboard shortcuts

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