errgroup

package
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Nov 15, 2022 License: BSD-3-Clause Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Check

func Check(err error) error

Check reports whether the "err" is not nil. If it is a group then it returns true if that or its children contains any error.

func Walk

func Walk(err error, visitor func(typ interface{}, err error)) error

Walk loops through each of the errors of "err". If "err" is *Group then it fires the "visitor" for each of its errors, including children. if "err" is *Error then it fires the "visitor" with its type and wrapped error. Otherwise it fires the "visitor" once with typ of nil and err as "err".

Types

type Error

type Error struct {
	Err  error       `json:"error" xml:"Error" yaml:"Error" toml:"Error" sql:"error"`
	Type interface{} `json:"type" xml:"Type" yaml:"Type" toml:"Type" sql:"type"`
}

Error implements the error interface. It is a special error type which keep the "Type" of the Group that it's created through Group's `Err` and `Errf` methods.

func (*Error) As

func (e *Error) As(target interface{}) bool

As reports whether the "target" can be used as &Error{target.Type: ?}.

func (*Error) Error

func (e *Error) Error() string

Error returns the error message of the "Err".

func (*Error) Is

func (e *Error) Is(err error) bool

Is reports whether the "err" is an *Error.

func (*Error) Unwrap

func (e *Error) Unwrap() error

Unwrap calls and returns the result of the "Err" Unwrap method or nil.

type Group

type Group struct {
	Type   interface{}
	Errors []error // []*Error

	// if true then this Group's Error method will return the messages of the errors made by this Group's Group method.
	// Defaults to true.
	IncludeChildren bool // it clones.
	// contains filtered or unexported fields
}

Group is an error container of a specific Type and can have child containers per type too.

func New

func New(typ interface{}) *Group

New returns a new empty Group.

func (*Group) Add

func (g *Group) Add(err error)

Add adds an error to the group.

func (*Group) Addf

func (g *Group) Addf(format string, args ...interface{}) error

Addf adds an error to the group like `fmt.Errorf` and returns it.

func (*Group) Err

func (g *Group) Err(err error) error

Err adds an error to the group, it transforms it to an Error type if necessary and returns it.

func (*Group) Errf

func (g *Group) Errf(format string, args ...interface{}) error

Errf adds an error like `fmt.Errorf` and returns it.

func (*Group) Error

func (g *Group) Error() (s string)

func (*Group) Group

func (g *Group) Group(typ interface{}) *Group

Group creates a new group of "typ" type, if does not exist, and returns it.

func (*Group) Unwrap

func (g *Group) Unwrap() error

Unwrap implements the dynamic std errors interface and it returns the parent Group.

Jump to

Keyboard shortcuts

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