v1.7.2
FIXED: * multierr race condition fix/now fully supports multithreading
This commit is contained in:
parent
3c543a05e7
commit
fd720f2b34
@ -69,6 +69,9 @@ func (e *MultiError) Error() (errStr string) {
|
|||||||
numErrs = len(e.Errors)
|
numErrs = len(e.Errors)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
e.lock.Lock()
|
||||||
|
defer e.lock.Unlock()
|
||||||
|
|
||||||
for idx, err := range e.Errors {
|
for idx, err := range e.Errors {
|
||||||
if (idx + 1) < numErrs {
|
if (idx + 1) < numErrs {
|
||||||
errStr += fmt.Sprintf("%v%v", err.Error(), e.ErrorSep)
|
errStr += fmt.Sprintf("%v%v", err.Error(), e.ErrorSep)
|
||||||
@ -87,6 +90,9 @@ func (e *MultiError) AddError(err error) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
e.lock.Lock()
|
||||||
|
defer e.lock.Unlock()
|
||||||
|
|
||||||
e.Errors = append(e.Errors, err)
|
e.Errors = append(e.Errors, err)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,9 +1,14 @@
|
|||||||
package multierr
|
package multierr
|
||||||
|
|
||||||
|
import (
|
||||||
|
`sync`
|
||||||
|
)
|
||||||
|
|
||||||
// MultiError is a type of error.Error that can contain multiple errors.
|
// MultiError is a type of error.Error that can contain multiple errors.
|
||||||
type MultiError struct {
|
type MultiError struct {
|
||||||
// Errors is a slice of errors to combine/concatenate when .Error() is called.
|
// Errors is a slice of errors to combine/concatenate when .Error() is called.
|
||||||
Errors []error `json:"errors"`
|
Errors []error `json:"errors"`
|
||||||
// ErrorSep is a string to use to separate errors for .Error(). The default is "\n".
|
// ErrorSep is a string to use to separate errors for .Error(). The default is "\n".
|
||||||
ErrorSep string `json:"separator"`
|
ErrorSep string `json:"separator"`
|
||||||
|
lock sync.Mutex
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user