multierror

package
v3.15.0-alpha.1 Latest Latest
Warning

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

Go to latest
Published: May 23, 2022 License: GPL-3.0 Imports: 3 Imported by: 0

Documentation

Overview

Package multierror contains code to manage multiple errors.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Union

type Union struct {
	// Children contains the underlying errors.
	Children []error

	// Root is the root error.
	Root error
}

Union is the logical union of several errors. The Union will appear to be the Root error, except that it will actually be possible to look deeper and see specific child errors that occurred using errors.As and errors.Is.

Example
package main

import (
	"errors"
	"fmt"

	"github.com/ooni/probe-cli/v3/internal/multierror"
)

func main() {
	root := errors.New("some error")
	me := multierror.New(root)
	check := errors.Is(me, root)
	fmt.Printf("%+v\n", check)
}
Output:

true

func New

func New(root error) *Union

New creates a new Union error instance.

func (*Union) Add

func (err *Union) Add(child error)

Add adds the specified child error to the Union error.

func (*Union) AddWithPrefix

func (err *Union) AddWithPrefix(prefix string, child error)

AddWithPrefix adds the specified child error to the Union error with the specified prefix before the child error.

func (Union) Error

func (err Union) Error() string

Error returns a string representation of the Union error.

func (Union) Is

func (err Union) Is(target error) bool

Is returns true (1) if the err.Root error is target or (2) if any err.Children error is target.

func (Union) Unwrap

func (err Union) Unwrap() error

Unwrap returns the Root error of the Union error.

Jump to

Keyboard shortcuts

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