errset

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Jan 7, 2021 License: BSD-2-Clause, Unlicense Imports: 0 Imported by: 1

README

errset is a trivial golang package that implements a slice of errors.

Build Status

The typical go idiom is to return an error or a tuple of (thing, error) from functions. This works well if a function performs exactly one task, but when a function does work which can reasonably partially fail, I found myself writing the same code over and over again. For example:

// CommitBatch commits as many things as it can.
func CommitBatch(things []Thing) error {
    errs := errset.ErrSet{}
    for _, thing := range things {
        err := Commit(thing)
        if err != nil {
            errs = append(errs, err)
        }
    }
    return errs.ReturnValue()   // nil if there were no errors
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ErrSet

type ErrSet []error

ErrSet represents a list of errors.

Example:

errs := ErrSet{}
for ... {
  if err := DoSomething(i); err != nil {
    errs = append(errs, err)
  }
}
return errs.ReturnValue()

func (ErrSet) Error

func (es ErrSet) Error() string

Error implements the error interface. It returns each error in the list concatenated together with "; ".

func (ErrSet) ReturnValue

func (es ErrSet) ReturnValue() error

ReturnValue returns the ErrSet object if at least one non-nill error is present or nil if there are no errors

Jump to

Keyboard shortcuts

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