multierror and multilogger cleaned up.

This commit is contained in:
2022-01-05 16:36:20 -05:00
parent 4addc44c0f
commit ef0a4d825d
3 changed files with 59 additions and 15 deletions

View File

@@ -39,12 +39,19 @@ func NewErrors(errs ...error) (err error) {
// NewMultiError will provide a MultiError (true type), optionally initialized with errors.
func NewMultiError(errs ...error) (m *MultiError) {
if errs == nil {
errs = make([]error, 0)
var realErrs []error = make([]error, 0)
if errs != nil {
for _, e := range errs {
if e == nil {
continue
}
realErrs = append(realErrs, e)
}
}
m = &MultiError{
Errors: errs,
Errors: realErrs,
ErrorSep: "\n",
}
@@ -83,3 +90,21 @@ func (e *MultiError) AddError(err error) {
e.Errors = append(e.Errors, err)
}
// Count returns the number of errors in a MultiError.
func (e *MultiError) Count() (n int) {
n = len(e.Errors)
return
}
// IsEmpty is a shorthand for testing if e.Errors is empty.
func (e *MultiError) IsEmpty() (empty bool) {
if e.Count() == 0 {
empty = true
}
return
}