Skip to content

Commit

Permalink
refactor: Don't build muliterrors for a single error
Browse files Browse the repository at this point in the history
For caller convenience multierror.New might be called with only a single
error in a list of errors.
In these cases there is no value of wrapping the error in a multierror
so New simply returns the single error it was called with.
  • Loading branch information
UnseenWizzard committed Jul 27, 2023
1 parent 3026ce9 commit 14448fd
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions internal/mutlierror/multierror.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ func (m MultiError) Error() string {
}

func New(errs ...error) error {
if len(errs) == 1 {
// callers might not always check this beforehand, but building a MultiError for a single error is useless
return errs[0]
}
return MultiError{
Errors: errs,
}
Expand Down

0 comments on commit 14448fd

Please sign in to comment.