From 38eaa6a9544695191bf72cc827463e22ecfa24a1 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Tue, 31 Mar 2020 09:39:58 -0700 Subject: [PATCH] Unwrap: one error can be returned directly --- multierror.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/multierror.go b/multierror.go index 33ebab3..d2bbbe9 100644 --- a/multierror.go +++ b/multierror.go @@ -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)