/
githubmirror
/
ydb-go-sdk
Обзор
Документация
Войти
/
githubmirror
/
ydb-go-sdk
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
internal/xerrors/stacktrace.go
71 строка
1 KB
Konstantin Prokopenko
Upgraded `golangci-lint` to v2.4.0 (#1925)
30 окт 2025, 18:53
Не верифицирован
30 окт 2025, 18:53
a0d9dfd
Код
Авторство
О чём код?
package xerrors import ( grpcStatus "google.golang.org/grpc/status" "github.com/ydb-platform/ydb-go-sdk/v3/internal/stack" ) const KeywordAt = "at" type withStackTraceOptions struct { skipDepth int } type WithStackTraceOption func(o *withStackTraceOptions) func WithSkipDepth(skipDepth int) WithStackTraceOption { return func(o *withStackTraceOptions) { o.skipDepth = skipDepth } } // WithStackTrace is a wrapper over original err with file:line identification func WithStackTrace(err error, opts ...WithStackTraceOption) error { if err == nil { return nil } options := withStackTraceOptions{} for _, opt := range opts { if opt != nil { opt(&options) } } if s, has := grpcStatus.FromError(err); has { return &stackTransportError{ stackError: stackError{ stackRecord: stack.Record(options.skipDepth + 1), err: err, }, status: s, } } return &stackError{ stackRecord: stack.Record(options.skipDepth + 1), err: err, } } type stackError struct { stackRecord string err error } func (e *stackError) Error() string { return e.err.Error() + " " + KeywordAt + " `" + e.stackRecord + "`" } func (e *stackError) Unwrap() error { return e.err } type stackTransportError struct { stackError status *grpcStatus.Status } func (e *stackTransportError) GRPCStatus() *grpcStatus.Status { return e.status }