Skip to content

Commit

Permalink
Unwrap: one error can be returned directly
Browse files Browse the repository at this point in the history
  • Loading branch information
mitchellh committed Mar 31, 2020
1 parent 58e4f18 commit 38eaa6a
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions multierror.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,11 @@ func (e *Error) Unwrap() error {
return nil
}

// If we have exactly one error, we can just return that directly.
if len(e.Errors) == 1 {
return e.Errors[0]
}

// Shallow copy the slice
errs := make([]error, len(e.Errors))
copy(errs, e.Errors)
Expand Down

0 comments on commit 38eaa6a

Please sign in to comment.