errslice

package module
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Oct 23, 2018 License: MIT Imports: 0 Imported by: 1 module, 1 package

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

errslice

GoDoc Build Status Codecov

errslice is simple library to handle multiple errors.

Documentation

Overview

Example (Assert)
package main

import (
	"fmt"
	"github.com/akaspin/errslice"
)

func main() {
	var err error
	for i := 0; i < 5; i++ {
		if i%2 == 0 {
			err = errslice.Append(err, fmt.Errorf("bad:%d", i))
		}
	}
	switch err1 := err.(type) {
	case errslice.Error:
		for _, err2 := range err1 {
			fmt.Println(err2)
		}
	case nil:
		fmt.Println("all good")
	default:
		fmt.Println(err1)
	}
}
Output:
bad:0
bad:2
bad:4
Example (Loop)
package main

import (
	"fmt"
	"github.com/akaspin/errslice"
)

func main() {
	var err error
	for i := 0; i < 5; i++ {
		if i%2 == 0 {
			err = errslice.Append(err, fmt.Errorf("bad:%d", i))
		}
	}
	fmt.Println(err)
}
Output:
bad:0,bad:2,bad:4

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Append

func Append(left, right error) (err error)

Append takes two errors and returns minimal result. If first argument is nil Append will return second and vise versa. If both arguments are nil Append will return nil.

If both arguments are not nil Append will combine them in Error

Types

type Error

type Error []error

Error is simple slice of errors

func (Error) Error

func (e Error) Error() (res string)

Error returns all collected errors delimited by comma

Jump to

Keyboard shortcuts

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