dcelasun commented on a change in pull request #2298:
URL: https://github.com/apache/thrift/pull/2298#discussion_r559154837



##########
File path: lib/go/thrift/exception.go
##########
@@ -26,19 +26,86 @@ 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()
+
+       if te, ok := err.(TException); ok {
+               switch te.TExceptionType() {
+               case TExceptionTypeTransport:
+                       if t, ok := err.(TTransportException); ok {
+                               return NewTTransportException(t.TypeId(), msg)
+                       }
+               case TExceptionTypeProtocol:
+                       if t, ok := err.(TProtocolException); ok {
+                               return 
NewTProtocolExceptionWithType(t.TypeId(), errors.New(msg))
+                       }
+               case TExceptionTypeApplication:
+                       if t, ok := err.(TApplicationException); ok {
+                               return NewTApplicationException(t.TypeId(), msg)
+                       }
+               }
+
+               return wrappedTException{
+                       err:            errors.New(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

Review comment:
       I think it's fine :) 




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to