summaryrefslogtreecommitdiff
path: root/vendor/github.com/uber/jaeger-client-go/thrift/exception.go
diff options
context:
space:
mode:
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.go86
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{}