-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy patherrors_join.go
More file actions
45 lines (40 loc) · 759 Bytes
/
errors_join.go
File metadata and controls
45 lines (40 loc) · 759 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
// Copyright (c) 2023 Benjamin Borbe All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package errors
func Join(errs ...error) error {
n := 0
for _, err := range errs {
if err != nil {
n++
}
}
if n == 0 {
return nil
}
e := &joinError{
errs: make([]error, 0, n),
}
for _, err := range errs {
if err != nil {
e.errs = append(e.errs, err)
}
}
return e
}
type joinError struct {
errs []error
}
func (e *joinError) Error() string {
var b []byte
b = append(b, '[', '\n')
for _, err := range e.errs {
b = append(b, err.Error()...)
b = append(b, '\n')
}
b = append(b, ']')
return string(b)
}
func (e *joinError) Unwrap() []error {
return e.errs
}