Skip to content

Commit 84ac340

Browse files
committed
feat: Make ErrorList threadsafe.
1 parent ed96bbd commit 84ac340

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

pkg/utils/errors.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,25 +18,33 @@ package utils
1818

1919
import (
2020
"strings"
21+
"sync"
2122
)
2223

2324
func NewErrorList() *ErrorList {
24-
return &ErrorList{}
25+
return &ErrorList{
26+
lock: &sync.RWMutex{},
27+
}
2528
}
2629

2730
// ErrorList is for when one error is not the cause of others.
2831
type ErrorList struct {
32+
lock sync.Locker
2933
errs []error
3034
}
3135

3236
func (e *ErrorList) Add(err error) {
37+
e.lock.Lock()
38+
defer e.lock.Unlock()
3339
if err == nil {
3440
return
3541
}
3642
e.errs = append(e.errs, err)
3743
}
3844

3945
func (e *ErrorList) Error() string {
46+
e.lock.Lock()
47+
defer e.lock.Unlock()
4048
msgs := []string{}
4149
for _, m := range e.errs {
4250
msgs = append(msgs, m.Error())

0 commit comments

Comments
 (0)