package errors
import "zgo.at/errors"
Package errors adds some useful error helpers.
Index ¶
- Variables
- func As(err error, target interface{}) bool
- func Errorf(f string, a ...interface{}) error
- func Is(err, target error) bool
- func Join(errs ...error) error
- func New(text string) error
- func Unwrap(err error) error
- func Wrap(err error, s string) error
- func Wrapf(err error, format string, a ...interface{}) error
- type Group
- func NewGroup(maxSize int) *Group
- func (g *Group) Append(err error) bool
- func (g Group) Error() string
- func (g *Group) ErrorOrNil() error
- func (g Group) Len() int
- func (g Group) List() []error
- func (g Group) Size() int
- type StackErr
- func (err StackErr) Error() string
- func (err StackErr) StackTrace() string
- func (err StackErr) Unwrap() error
- type StackTracer
Variables ¶
var ( // Package to add trace lines for; if blank all traces are added. Package string // StackSize is the maximum stack sized added to errors. Set to 0 to // disable. StackSize int = 32 )
Functions ¶
func As ¶
func Errorf ¶
func Is ¶
func Join ¶
func New ¶
func Unwrap ¶
func Wrap ¶
Wrap an error with fmt.Errorf(), returning nil if err is nil.
func Wrapf ¶
Wrapf an error with fmt.Errorf(), returning nil if err is nil.
Types ¶
type Group ¶
type Group struct { // Maximum number of errors; calls to Append() won't do anything if the // number of errors is larger than this. MaxSize int // contains filtered or unexported fields }
Group multiple errors.
func NewGroup ¶
NewGroup create a new Group instance. It will record a maximum of maxSize errors. Set to 0 for no limit.
func (*Group) Append ¶
Append a new error to the list; this is thread-safe.
It won't do anything if the error is nil, in which case it will return false. This makes appending errors in a loop slightly nicer:
for { err := do() if errors.Append(err) { continue } }
func (Group) Error ¶
func (*Group) ErrorOrNil ¶
ErrorOrNil returns itself if there are errors, or nil otherwise.
It avoids an if-check at the end:
return errs.ErrorOrNil()
func (Group) Len ¶
Len returns the number of errors we have stored.
func (Group) List ¶
List all the errors; returns nil if there are no errors.
func (Group) Size ¶
Size returns the number of errors that occured.
type StackErr ¶
type StackErr struct {
// contains filtered or unexported fields
}
func (StackErr) Error ¶
func (StackErr) StackTrace ¶
func (StackErr) Unwrap ¶
type StackTracer ¶
type StackTracer interface { StackTrace() string }
Source Files ¶
errors.go
- Version
- v1.4.0 (latest)
- Published
- Nov 1, 2024
- Platform
- linux/amd64
- Imports
- 7 packages
- Last checked
- 2 weeks ago –
Tools for package owners.