Fork of xerrors with explicit Wrap instead of %w.
Clear is better than clever.
go get github.com/go-faster/errors
errors.Wrap(err, "message")
Wrap is the most explicit way to wrap errorsfmt.Errorf("foo: %w", err) is implicit, redundant and error-prone"foo: %w" is implicit, redundant and slowerrors has no caller stack traceWrap(nil, "msg") returns a non-nil error, matching fmt.Errorf("msg: %w", err)
with a nil err (and unlike pkg/errors, which returns nil). Wrap only after
checking err != nil:
if err := do(); err != nil {
return errors.Wrap(err, "do")
}
return nil
Call errors.DisableTrace or use build tag noerrtrace.
Generic type assertion for errors.
// Into finds the first error in err's chain that matches target type T, and if so, returns it.
//
// Into is type-safe alternative to As.
func Into[T error](err error) (val T, ok bool)
if pathError, ok := errors.Into[*os.PathError](err); ok {
fmt.Println("Failed at path:", pathError.Path)
}
Must is a generic helper, like template.Must, that wraps a call to a function returning (T, error) and panics if the error is non-nil.
func Must[T any](val T, err error) T
BSD-3-Clause, same as Go sources
Overall
Maintained
Code review
Go module
Latest release
Releases this year
Fork of xerrors with explicit Wrap instead of %w.
Clear is better than clever.
go get github.com/go-faster/errors
errors.Wrap(err, "message")
Wrap is the most explicit way to wrap errorsfmt.Errorf("foo: %w", err) is implicit, redundant and error-prone"foo: %w" is implicit, redundant and slowerrors has no caller stack traceWrap(nil, "msg") returns a non-nil error, matching fmt.Errorf("msg: %w", err)
with a nil err (and unlike pkg/errors, which returns nil). Wrap only after
checking err != nil:
if err := do(); err != nil {
return errors.Wrap(err, "do")
}
return nil
Call errors.DisableTrace or use build tag noerrtrace.
Generic type assertion for errors.
// Into finds the first error in err's chain that matches target type T, and if so, returns it.
//
// Into is type-safe alternative to As.
func Into[T error](err error) (val T, ok bool)
if pathError, ok := errors.Into[*os.PathError](err); ok {
fmt.Println("Failed at path:", pathError.Path)
}
Must is a generic helper, like template.Must, that wraps a call to a function returning (T, error) and panics if the error is non-nil.
func Must[T any](val T, err error) T
BSD-3-Clause, same as Go sources
Overall
Maintained
Code review
Go module
Latest release
Releases this year