Skip to main content

github.com/hashicorp/go-multierror

Go API reference for the package github.com/hashicorp/go-multierror.

Public API

Function: Append

Canonical path: github.com/hashicorp/go-multierror.Append

Declared in: append.go

Signature

func Append(err error, errs ...error) *Error {}

Summary

Append is a helper function that will append more errors onto an Error in order to create a larger multi-error.

Behavior

If err is not a multierror.Error, then it will be turned into one. If any of the errs are multierr.Error, they will be flattened one level into err. Any nil errors within errs will be ignored. If err is nil, a new *Error will be returned.

Parameters

  • err: The initial error to which additional errors are appended. If this is nil, a new Error is returned.
  • errs: A variadic list of errors to append. Any nil values in this list are ignored, and any multierr.Error values are flattened one level.

Returns

  • Return value 1: Returns a pointer to a multierror.Error containing the combined errors.

Function: Flatten

Canonical path: github.com/hashicorp/go-multierror.Flatten

Declared in: flatten.go

Signature

func Flatten(err error) error {}

Summary

Flatten flattens the given error, merging any *Errors together into a single *Error.

Behavior

If the input error is not a multierror.Error, it is returned as-is. Otherwise, it merges nested multierrors into a single flat Error.

Parameters

  • err: The error to be flattened.

Returns

  • Return value 1: Returns the flattened error, or the original error if it was not a multierror.Error.

Function: ListFormatFunc

Canonical path: github.com/hashicorp/go-multierror.ListFormatFunc

Declared in: format.go

Signature

func ListFormatFunc(es []error) string {}

Summary

ListFormatFunc is a basic formatter that outputs the number of errors that occurred along with a bullet point list of the errors.

Behavior

Formats a slice of errors into a string starting with the count of errors followed by a bulleted list.

Parameters

  • es: A slice of errors to be formatted.

Returns

  • Return value 1: Returns a formatted string describing the errors.

Function: Prefix

Canonical path: github.com/hashicorp/go-multierror.Prefix

Declared in: prefix.go

Signature

func Prefix(err error, prefix string) error {}

Summary

Prefix is a helper function that will prefix some text to the given error. If the error is a multierror.Error, then it will be prefixed to each wrapped error.

Behavior

This is useful to use when appending multiple multierrors together in order to give better scoping.

Parameters

  • err: The error to be prefixed. If nil, the function returns nil.
  • prefix: The string to prepend to the error message.

Returns

  • Return value 1: Returns an error where the message is prefixed. If the input was a multierror.Error, each wrapped error is prefixed.

Receiver Method: Error

Canonical path: github.com/hashicorp/go-multierror.Error.Error

Declared in: multierror.go

Signature

func (e *Error) Error() string {}

Summary

Error implements the error interface for the Error type.

Behavior

Uses the ErrorFormat function defined on the Error struct to format the output. If ErrorFormat is nil, it defaults to ListFormatFunc.

Returns

  • Return value 1: Returns the formatted error string.

Receiver Method: ErrorOrNil

Canonical path: github.com/hashicorp/go-multierror.Error.ErrorOrNil

Declared in: multierror.go

Signature

func (e *Error) ErrorOrNil() error {}

Summary

ErrorOrNil returns an error interface if this Error represents a list of errors, or returns nil if the list of errors is empty. This function is useful at the end of accumulation to make sure that the value returned represents the existence of errors.

Behavior

Checks if the Error receiver is nil or if its internal list of errors is empty.

Returns

  • Return value 1: Returns nil if there are no errors, otherwise returns the Error itself as an error interface.

Receiver Method: GoString

Canonical path: github.com/hashicorp/go-multierror.Error.GoString

Declared in: multierror.go

Signature

func (e *Error) GoString() string {}

Summary

GoString implements the fmt.GoStringer interface.

Behavior

Formats the Error struct using the default Go syntax representation with a pointer prefix.

Returns

  • Return value 1: Returns the Go string representation of the Error.

Receiver Method: Len

Canonical path: github.com/hashicorp/go-multierror.Error.Len

Declared in: sort.go

Signature

func (err *Error) Len() int {}

Summary

Len implements sort.Interface function for length

Behavior

Returns 0 if the receiver is nil, otherwise returns the number of wrapped errors.

Returns

  • Return value 1: Returns the integer length of the Errors slice.

Receiver Method: Less

Canonical path: github.com/hashicorp/go-multierror.Error.Less

Declared in: sort.go

Signature

func (err Error) Less(i, j int) bool {}

Summary

Less implements sort.Interface function for determining order

Behavior

Compares the error strings of the elements at indices i and j.

Parameters

  • i: The index of the first element to compare.
  • j: The index of the second element to compare.

Returns

  • Return value 1: Returns true if the error string at index i is lexicographically less than the error string at index j.

Receiver Method: Swap

Canonical path: github.com/hashicorp/go-multierror.Error.Swap

Declared in: sort.go

Signature

func (err Error) Swap(i, j int) {}

Summary

Swap implements sort.Interface function for swapping elements

Behavior

Swaps the errors at the specified indices within the Errors slice.

Parameters

  • i: The index of the first element to swap.
  • j: The index of the second element to swap.

Receiver Method: Unwrap

Canonical path: github.com/hashicorp/go-multierror.Error.Unwrap

Declared in: multierror.go

Signature

func (e *Error) Unwrap() error {}

Summary

Unwrap returns an error from Error (or nil if there are no errors). This error returned will further support Unwrap to get the next error, etc. The order will match the order of Errors in the multierror.Error at the time of calling.

Behavior

The resulting error supports errors.As/Is/Unwrap so you can continue to use the stdlib errors package to introspect further. This will perform a shallow copy of the errors slice. Any errors appended to this error after calling Unwrap will not be available until a new Unwrap is called on the multierror.Error.

Returns

  • Return value 1: Returns nil if there are no errors, the single error if only one exists, or a chain of errors if multiple exist.

Receiver Method: WrappedErrors

Canonical path: github.com/hashicorp/go-multierror.Error.WrappedErrors

Declared in: multierror.go

Signature

func (e *Error) WrappedErrors() []error {}

Summary

WrappedErrors returns the list of errors that this Error is wrapping. It is an implementation of the errwrap.Wrapper interface so that multierror.Error can be used with that library.

Behavior

This method is not safe to be called concurrently. Unlike accessing the Errors field directly, this function also checks if the multierror is nil to prevent a null-pointer panic. It satisfies the errwrap.Wrapper interface.

Returns

  • Return value 1: Returns the internal slice of errors, or nil if the receiver is nil.

Receiver Method: Go

Canonical path: github.com/hashicorp/go-multierror.Group.Go

Declared in: group.go

Signature

func (g *Group) Go(f func() error) {}

Summary

Go calls the given function in a new goroutine.

Behavior

If the function returns an error it is added to the group multierror which is returned by Wait.

Parameters

  • f: The function to execute in a new goroutine. It should return an error or nil.

Receiver Method: Wait

Canonical path: github.com/hashicorp/go-multierror.Group.Wait

Declared in: group.go

Signature

func (g *Group) Wait() *Error {}

Summary

Wait blocks until all function calls from the Go method have returned, then returns the multierror.

Behavior

Wait blocks until all function calls from the Go method have returned.

Returns

  • Return value 1: Wait returns a pointer to an Error containing the multierror.

Named Type: ErrorFormatFunc

Canonical path: github.com/hashicorp/go-multierror.ErrorFormatFunc

Declared in: format.go

Signature

type ErrorFormatFunc func([]error) string

Summary

ErrorFormatFunc is a function callback that is called by Error to turn the list of errors into a string.

Struct: Error

Canonical path: github.com/hashicorp/go-multierror.Error

Declared in: multierror.go

Signature

type Error struct {
Errors []error
ErrorFormat ErrorFormatFunc
}

Summary

Error is an error type to track multiple errors. This is used to accumulate errors in cases and return them as a single "error".

Struct: Group

Canonical path: github.com/hashicorp/go-multierror.Group

Declared in: group.go

Signature

type Group struct {
// contains unexported members
}

Summary

Group is a collection of goroutines which return errors that need to be coalesced.