aggregaterr

package module
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Aug 26, 2022 License: MIT Imports: 1 Imported by: 0

README

go-aggregate-error

Return multiple errors from your Go function.

Example:

func Foo() error {
    errs := aggregaterr.NewError()
    for {
        // Do something that returns error but should not break the loop.
        err := foo()
        if err != nil {
            errs.Append(err)
            continue
        }
    }
    return errs.Return()
}

Error.Return returns nil if no error was appended. Otherwise it returns itself.

Documentation

Overview

Package aggregaterr provides an error type storing multiple errors.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Error

type Error struct {
	// Prefix is used in the error message before any of the
	// aggregated errors.
	Prefix string
	// Errors are used in the error message by concatenating their
	// message.
	Errors []error
}

Error allows returning several errors while satisfying the error interface.

func New

func New(prefix string) *Error

func (*Error) Append

func (a *Error) Append(err error)

func (*Error) Error

func (a *Error) Error() string

Error returns messages from all errors concatenated with semicolon.

func (*Error) Return

func (a *Error) Return() error

Jump to

Keyboard shortcuts

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