Skip to content

Commit 38eaa6a

Browse files
committed
Unwrap: one error can be returned directly
1 parent 58e4f18 commit 38eaa6a

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

multierror.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,11 @@ func (e *Error) Unwrap() error {
6868
return nil
6969
}
7070

71+
// If we have exactly one error, we can just return that directly.
72+
if len(e.Errors) == 1 {
73+
return e.Errors[0]
74+
}
75+
7176
// Shallow copy the slice
7277
errs := make([]error, len(e.Errors))
7378
copy(errs, e.Errors)

0 commit comments

Comments
 (0)