errset

package module
v0.0.0-...-f78d65d Latest Latest
Warning

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

Go to latest
Published: Feb 19, 2016 License: Unlicense Imports: 0 Imported by: 12 modules, 12 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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
⌂ 换网址