diff --git a/libs/errs/aggregate.go b/libs/errs/aggregate.go index ba856100b30..83cbc5ca978 100644 --- a/libs/errs/aggregate.go +++ b/libs/errs/aggregate.go @@ -27,6 +27,15 @@ func FromMany(errors ...error) error { return aggregateErr } +// Count returns the number of errors aggregated in err. +// Returns 0 if err was not created by FromMany. +func Count(err error) int { + if agg, ok := err.(*aggregateError); ok { + return len(agg.errors) + } + return 0 +} + func (ce *aggregateError) Error() string { var b []byte for i, err := range ce.errors {