refactor(core/errorx): use errors.Join simplify error handle (#4289)

This commit is contained in:
chentong
2024-08-03 11:00:59 +08:00
committed by GitHub
parent ff6ee25d23
commit 8689a6247e
2 changed files with 36 additions and 11 deletions

View File

@@ -1,7 +1,7 @@
package errorx
import (
"bytes"
"errors"
"sync"
)
@@ -52,14 +52,10 @@ func (be *BatchError) NotNil() bool {
// Error returns a string that represents inside errors.
func (ea errorArray) Error() string {
var buf bytes.Buffer
for i := range ea {
if i > 0 {
buf.WriteByte('\n')
}
buf.WriteString(ea[i].Error())
}
return buf.String()
return errors.Join(ea...).Error()
}
// Unwrap combine the errors in the errorArray into a single error return
func (ea errorArray) Unwrap() error {
return errors.Join(ea...)
}