errorlist

package
v0.0.0-...-31509f8 Latest Latest
Warning

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

Go to latest
Published: Apr 26, 2024 License: Apache-2.0 Imports: 2 Imported by: 0

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Append

func Append(a, b error, e ...error) error

Append takes at least two errors and combines them into a list. The rules are as follows:

  • If all of the errors being appended are nil, Append returns nil.
  • If exactly one of the errors being appended is non-nil, Append returns that error unchanged.
  • Otherwise, Append returns a slice of errors (wrapped in an Errors instance) consisting of the inputs, minus any nil errors.

If any of the passed errors are themselves Errors slices, their contents will be flattened into the resulting error. This behavior can be prevented by wrapping input Errors slices in their own context, for example using fmt.Errorf.

Example
package main

import (
	"errors"
	"fmt"

	"github.com/greenplum-db/gpupgrade/utils/errorlist"
)

func main() {
	errs := make(chan error)

	go func() {
		errs <- errors.New("one")
		errs <- errors.New("two")
		errs <- errors.New("three")
	}()

	var err error
	for i := 0; i < 3; i++ {
		err = errorlist.Append(err, <-errs)
	}

	fmt.Println(err)

}
Output:

3 errors occurred:
	* one
	* two
	* three

Types

type Errors

type Errors []error

Errors is a slice of error values that can be treated like a single error value. Use Append to create Errors instances.

func (Errors) Error

func (e Errors) Error() string

func (Errors) Len

func (e Errors) Len() int

func (Errors) Less

func (e Errors) Less(i, j int) bool

func (Errors) Swap

func (e Errors) Swap(i, j int)

Jump to

Keyboard shortcuts

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