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



##########
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),

Review comment:
       @tte
   
   1. the old `PrependError` doesn't keep the original error either, so this is 
not a regression :)
   2. that being said, this is a reasonable proposal and trivial to implement 
so I'll just do it
   3. I'm curious, which TProtocol/TTransport combination do you use to 
actually get `context.Canceled` to be wrapped under those `ReadFieldX` 
functions? I don't think any of the TProtocol implementation would return 
`context.Canceled` as the error




----------------------------------------------------------------
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