diff options
author | dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> | 2021-05-31 12:55:49 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-05-31 12:55:49 +0000 |
commit | d657a070d36e206b1312db48c26cb72cd26e7202 (patch) | |
tree | 06f87349fb10e30f6977b6e612e2d966a9407e51 /vendor/github.com/uber/jaeger-client-go/thrift/exception.go | |
parent | c1c18039dca2d0967082e63935c2052cd089570a (diff) | |
download | podman-d657a070d36e206b1312db48c26cb72cd26e7202.tar.gz podman-d657a070d36e206b1312db48c26cb72cd26e7202.tar.bz2 podman-d657a070d36e206b1312db48c26cb72cd26e7202.zip |
Bump github.com/uber/jaeger-client-go
Bumps [github.com/uber/jaeger-client-go](https://github.com/uber/jaeger-client-go) from 2.28.0+incompatible to 2.29.1+incompatible.
- [Release notes](https://github.com/uber/jaeger-client-go/releases)
- [Changelog](https://github.com/jaegertracing/jaeger-client-go/blob/master/CHANGELOG.md)
- [Commits](https://github.com/uber/jaeger-client-go/compare/v2.28.0...v2.29.1)
Signed-off-by: dependabot[bot] <support@github.com>
Diffstat (limited to 'vendor/github.com/uber/jaeger-client-go/thrift/exception.go')
-rw-r--r-- | vendor/github.com/uber/jaeger-client-go/thrift/exception.go | 86 |
1 files changed, 79 insertions, 7 deletions
diff --git a/vendor/github.com/uber/jaeger-client-go/thrift/exception.go b/vendor/github.com/uber/jaeger-client-go/thrift/exception.go index ea8d6f661..53bf862ea 100644 --- a/vendor/github.com/uber/jaeger-client-go/thrift/exception.go +++ b/vendor/github.com/uber/jaeger-client-go/thrift/exception.go @@ -26,19 +26,91 @@ import ( // Generic Thrift exception type TException interface { error + + TExceptionType() TExceptionType } // Prepends additional information to an error without losing the Thrift exception interface func PrependError(prepend string, err error) error { - if t, ok := err.(TTransportException); ok { - return NewTTransportException(t.TypeId(), prepend+t.Error()) + msg := prepend + err.Error() + + var te TException + if errors.As(err, &te) { + switch te.TExceptionType() { + case TExceptionTypeTransport: + if t, ok := err.(TTransportException); ok { + return prependTTransportException(prepend, t) + } + case TExceptionTypeProtocol: + if t, ok := err.(TProtocolException); ok { + return prependTProtocolException(prepend, t) + } + case TExceptionTypeApplication: + var t TApplicationException + if errors.As(err, &t) { + return NewTApplicationException(t.TypeId(), msg) + } + } + + return wrappedTException{ + err: err, + msg: msg, + tExceptionType: te.TExceptionType(), + } + } + + return errors.New(msg) +} + +// TExceptionType is an enum type to categorize different "subclasses" of TExceptions. +type TExceptionType byte + +// TExceptionType values +const ( + TExceptionTypeUnknown TExceptionType = iota + TExceptionTypeCompiled // TExceptions defined in thrift files and generated by thrift compiler + TExceptionTypeApplication // TApplicationExceptions + TExceptionTypeProtocol // TProtocolExceptions + TExceptionTypeTransport // TTransportExceptions +) + +// WrapTException wraps an error into TException. +// +// If err is nil or already TException, it's returned as-is. +// Otherwise it will be wraped into TException with TExceptionType() returning +// TExceptionTypeUnknown, and Unwrap() returning the original error. +func WrapTException(err error) TException { + if err == nil { + return nil } - if t, ok := err.(TProtocolException); ok { - return NewTProtocolExceptionWithType(t.TypeId(), errors.New(prepend+err.Error())) + + if te, ok := err.(TException); ok { + return te } - if t, ok := err.(TApplicationException); ok { - return NewTApplicationException(t.TypeId(), prepend+t.Error()) + + return wrappedTException{ + err: err, + msg: err.Error(), + tExceptionType: TExceptionTypeUnknown, } +} + +type wrappedTException struct { + err error + msg string + tExceptionType TExceptionType +} - return errors.New(prepend + err.Error()) +func (w wrappedTException) Error() string { + return w.msg } + +func (w wrappedTException) TExceptionType() TExceptionType { + return w.tExceptionType +} + +func (w wrappedTException) Unwrap() error { + return w.err +} + +var _ TException = wrappedTException{} |