multierror

package
v3.24.0 Latest Latest
Warning

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

Go to latest
Published: Nov 25, 2024 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

func BuildErrorString

func BuildErrorString(prefix string, errs ...error) string

BuildErrorString builds the error string returned by *Union.Error using the given prefix string as the prefix and the given list of errors.

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/legacy/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.

QUIRK: we cannot change this function to be `Unwrap() []error` as explained by https://github.com/ooni/probe-cli/pull/1587.

Jump to

Keyboard shortcuts

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