Repository: thrift
Updated Branches:
  refs/heads/master ff4a8edd5 -> b92573955


THRIFT-3335 Ruby server does not handle processor exception
Client: Ruby
Patch: Nobuaki Sukegawa <[email protected]>

This closes #612


Project: http://git-wip-us.apache.org/repos/asf/thrift/repo
Commit: http://git-wip-us.apache.org/repos/asf/thrift/commit/b9257395
Tree: http://git-wip-us.apache.org/repos/asf/thrift/tree/b9257395
Diff: http://git-wip-us.apache.org/repos/asf/thrift/diff/b9257395

Branch: refs/heads/master
Commit: b9257395509bc6fbcc2f77e0f9237e39f7ec1a7d
Parents: ff4a8ed
Author: Jens Geyer <[email protected]>
Authored: Mon Sep 21 22:36:45 2015 +0200
Committer: Jens Geyer <[email protected]>
Committed: Mon Sep 21 22:36:45 2015 +0200

----------------------------------------------------------------------
 lib/rb/lib/thrift/processor.rb | 21 ++++++++++++++++-----
 1 file changed, 16 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/thrift/blob/b9257395/lib/rb/lib/thrift/processor.rb
----------------------------------------------------------------------
diff --git a/lib/rb/lib/thrift/processor.rb b/lib/rb/lib/thrift/processor.rb
index 5d9e0a1..b96fb43 100644
--- a/lib/rb/lib/thrift/processor.rb
+++ b/lib/rb/lib/thrift/processor.rb
@@ -26,16 +26,18 @@ module Thrift
     def process(iprot, oprot)
       name, type, seqid  = iprot.read_message_begin
       if respond_to?("process_#{name}")
-        send("process_#{name}", seqid, iprot, oprot)
+        begin
+          send("process_#{name}", seqid, iprot, oprot)
+        rescue => e
+          x = ApplicationException.new(ApplicationException::INTERNAL_ERROR, 
'Internal error')
+          write_error(x, oprot, name, seqid)
+        end
         true
       else
         iprot.skip(Types::STRUCT)
         iprot.read_message_end
         x = ApplicationException.new(ApplicationException::UNKNOWN_METHOD, 
'Unknown function '+name)
-        oprot.write_message_begin(name, MessageTypes::EXCEPTION, seqid)
-        x.write(oprot)
-        oprot.write_message_end
-        oprot.trans.flush
+        write_error(x, oprot, name, seqid)
         false
       end
     end
@@ -53,5 +55,14 @@ module Thrift
       oprot.write_message_end
       oprot.trans.flush
     end
+
+    def write_error(err, oprot, name, seqid)
+      p 'write_error'
+      oprot.write_message_begin(name, MessageTypes::EXCEPTION, seqid)
+      err.write(oprot)
+      oprot.write_message_end
+      oprot.trans.flush
+      p 'write_error end'
+    end
   end
 end

Reply via email to