This commit is contained in:
2026-07-06 12:35:59 +08:00
parent 59becf9e16
commit e8664ca2d7
3 changed files with 51 additions and 3 deletions

View File

@@ -1,6 +1,7 @@
package shumai
import (
"errors"
"fmt"
)
@@ -99,10 +100,23 @@ func IsShumaiError(err error) bool {
return ok
}
// GetShumaiError 获取数脉错误
// GetShumaiError 获取数脉错误(支持 errors.Join 包装)
func GetShumaiError(err error) *ShumaiError {
if err == nil {
return nil
}
type unwrapMulti interface {
Unwrap() []error
}
if u, ok := err.(unwrapMulti); ok {
for _, e := range u.Unwrap() {
if se := GetShumaiError(e); se != nil {
return se
}
}
}
if e, ok := err.(*ShumaiError); ok {
return e
}
return nil
return GetShumaiError(errors.Unwrap(err))
}