fix: BatchError.Add() non thread safe (#3946)

This commit is contained in:
chentong
2024-03-02 00:32:39 +08:00
committed by GitHub
parent 5263805b3b
commit ec41880476
2 changed files with 30 additions and 3 deletions

View File

@@ -1,10 +1,14 @@
package errorx
import "bytes"
import (
"bytes"
"sync"
)
type (
// A BatchError is an error that can hold multiple errors.
BatchError struct {
mu sync.Mutex
errs errorArray
}
@@ -13,6 +17,9 @@ type (
// Add adds errs to be, nil errors are ignored.
func (be *BatchError) Add(errs ...error) {
be.mu.Lock()
defer be.mu.Unlock()
for _, err := range errs {
if err != nil {
be.errs = append(be.errs, err)