diff --git a/src/errors/join.go b/src/errors/join.go index f66534c4c3..349fc06ed9 100644 --- a/src/errors/join.go +++ b/src/errors/join.go @@ -44,24 +44,17 @@ type joinError struct { func (e *joinError) Error() string { // Since Join returns nil if every value in errs is nil, // e.errs cannot be empty. - // TODO: get rid of case 0 - switch len(e.errs) { - case 0: // Impossible but handle. - return "" - case 1: + if len(e.errs) == 1 { return e.errs[0].Error() } - // To avoid doubling the number of Error calls, skip preallocating - // the slice on overflow and let the runtime handle the panic. b := []byte(e.errs[0].Error()) for _, err := range e.errs[1:] { b = append(b, '\n') b = append(b, err.Error()...) } // At this point, b has at least one byte '\n'. - // TODO: replace with unsafe.String(&b[0], len(b)) - return unsafe.String(unsafe.SliceData(b), len(b)) + return unsafe.String(&b[0], len(b)) } func (e *joinError) Unwrap() []error {