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 subsequent errors are appended. If this is nil, a new Error is created. If it is not a multierror.Error, it is converted into one.
- errs: A variadic list of errors to append to the initial error. Any nil errors in this list are ignored, and any multierror.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 multierror.Error instances into a single flat multierror.Error.
Parameters
- err: The error to be flattened.
Returns
- Return value 1: Returns the flattened 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. If there is exactly one error, it returns a specific singular format; otherwise, it returns a bulleted list prefixed by the total error count.
Parameters
- es: A slice of errors to be formatted.
Returns
- Return value 1: Returns a formatted string representing the list of 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 which the prefix will be applied. If nil, the function returns nil.
- prefix: The string to prefix to the error message.
Returns
- Return value 1: Returns an error where the message is prefixed with the specified text. 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 standard error interface for the Error type.
Behavior
Uses the ErrorFormat function field to format the contained errors. 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 error list is empty.
Returns
- Return value 1: Returns nil if there are no errors; otherwise, returns the Error instance 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 fmt.GoStringer for the Error type.
Behavior
Formats the Error using the Go-syntax representation of the underlying struct.
Returns
- Return value 1: Returns a string representing the Go-syntax 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
Calculates the number of errors contained within the multierror. Returns 0 if the receiver is nil.
Returns
- Return value 1: Returns the count of errors as an integer.
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 two errors in the multierror by their string representations to determine their relative order.
Parameters
- i: The index of the first error to compare.
- j: The index of the second error to compare.
Returns
- Return value 1: Returns true if the error at index i is lexicographically less than the error 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 positions of two errors within the internal error slice.
Parameters
- i: The index of the first error to swap.
- j: The index of the second error 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 no errors exist. If exactly one error exists, it returns that error directly. If multiple errors exist, it returns a chained error representation based on a shallow copy of the error slice.
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. Returns 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 be executed in a new goroutine. It must 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.