| 1 | // Copyright 2023 The Go Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style |
| 3 | // license that can be found in the LICENSE file. |
| 4 | |
| 5 | //go:build go1.19 && !go1.20 |
| 6 | |
| 7 | package slogtest |
| 8 | |
| 9 | import ( |
| 10 | "errors" |
| 11 | "strings" |
| 12 | ) |
| 13 | |
| 14 | func errorsJoin(errs ...error) error { |
| 15 | var b strings.Builder |
| 16 | for _, err := range errs { |
| 17 | if err != nil { |
| 18 | b.WriteString(err.Error()) |
| 19 | b.WriteByte('\n') |
| 20 | } |
| 21 | } |
| 22 | s := b.String() |
| 23 | if len(s) == 0 { |
| 24 | return nil |
| 25 | } |
| 26 | return errors.New(s) |
| 27 | } |