/
githubmirror
/
ydb-go-sdk
Обзор
Документация
Войти
/
githubmirror
/
ydb-go-sdk
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
sugar/errors.go
45 строк
1 KB
Aleksey Myasnikov
* Added `sugar.PrintErrorWithoutStack` and `sugar.UnwrapError` helpers (#1818)
23 июн 2025, 15:28
Не верифицирован
23 июн 2025, 15:28
877b74f
Код
Авторство
О чём код?
package sugar import ( "regexp" "github.com/ydb-platform/ydb-go-sdk/v3/internal/xerrors" ) var re = regexp.MustCompile("\\s+" + xerrors.KeywordAt + "\\s+`[^`]+`") func removeStackRecords(s string) string { // Some error constructors (such as fmt.Errorf, grpcStatus.Error) are serializing the error string at the // construction time. Thats why the "true way" with casting the wrapped error into *xerrors.stackError // has no effect return re.ReplaceAllString(s, "") } // PrintErrorWithoutStack removes stacktrace records from error string func PrintErrorWithoutStack(err error) string { return removeStackRecords(err.Error()) } // UnwrapError unwraps the source error into its root errors func UnwrapError(err error) (errs []error) { if err == nil { return nil } if x, has := err.(interface { Unwrap() error }); has { return UnwrapError(x.Unwrap()) } else if x, has := err.(interface { Unwrap() []error }); has { for _, xx := range x.Unwrap() { errs = append(errs, UnwrapError(xx)...) } return errs } else if len(errs) == 0 { return []error{err} } return errs }