Documentation
¶
Overview ¶
Package erc provides a simple/fast error aggregation tool for collecting and aggregating errors. The tools are compatible with go's native error wrapping, and are generally safe for use from multiple goroutines, so can simplify error collection patterns in worker-pool patterns.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Collector ¶
type Collector struct {
// contains filtered or unexported fields
}
Collector is a simplified version of the error collector in github.com/tychoish/emt. The collector is thread safe and aggregates errors which can be resolved as a single error. The constituent errors (and flattened, in the case of wrapped errors), are an *erc.Stack object, which can be introspected as needed.
func (*Collector) Check ¶
Check executes a simple function and if it returns an error, adds it to the collector, primarily for use in defer statements.
func (*Collector) HasErrors ¶
HasErrors returns true if there are any underlying errors, and false otherwise.
func (*Collector) Iterator ¶
Iterator produces an iterator for all errors present in the collector. The iterator proceeds from the current error to the oldest error, and will not observe new errors added to the collector. While the iterator isn't safe for current access from multiple go routines, the sequence of errors stored are not modified after creation.
type Stack ¶
type Stack struct {
// contains filtered or unexported fields
}
Stack represents the error type returned by an ErrorCollector when it has more than one error. The implementation provides support for errors.Unwrap and errors.Is, and provides an Errors() method which returns a slice of the constituent errors for additional use.
func (*Stack) Error ¶
Error produces the aggregated error strings from this method. If the error at the current layer is nil.
func (*Stack) Is ¶
Is calls errors.Is on the underlying error to provied compatibility with errors.Is, which takes advantage of this interface.
func (*Stack) Iterator ¶
Iterator returns an iterator object over the contents of the stack. While the content of the iterator is immutable and will not observe new errors added to the stack, the iterator itself is not safe for concurrent access, and must only be used from one goroutine, or with a synchronized approach. You may create multiple Iterators on the same stack without issue.