Various Thrift fixes, including Application Exception support in Ruby, better errror messages across languages, etc.

Reviewed By: thrift


git-svn-id: https://svn.apache.org/repos/asf/incubator/thrift/trunk@665058 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/compiler/cpp/cleanup.sh b/compiler/cpp/cleanup.sh
index 7dea388..e2ab8f8 100755
--- a/compiler/cpp/cleanup.sh
+++ b/compiler/cpp/cleanup.sh
@@ -1,5 +1,6 @@
 #!/bin/sh
 
+make clean 1>/dev/null 2>/dev/null
 rm -rf \
 AUTHORS \
 ChangeLog \
diff --git a/compiler/cpp/configure.ac b/compiler/cpp/configure.ac
index 5408146..f6aa0f5 100644
--- a/compiler/cpp/configure.ac
+++ b/compiler/cpp/configure.ac
@@ -44,4 +44,6 @@
 
 AC_PROG_LIBTOOL
 
+AC_PROG_MAKE_SET
+
 AC_OUTPUT(Makefile)
diff --git a/compiler/cpp/src/generate/t_rb_generator.cc b/compiler/cpp/src/generate/t_rb_generator.cc
index 7672030..6e29352 100644
--- a/compiler/cpp/src/generate/t_rb_generator.cc
+++ b/compiler/cpp/src/generate/t_rb_generator.cc
@@ -705,12 +705,18 @@
         indent() << "def " << function_signature(&recv_function) << endl;
       indent_up();
 
-      f_service_ <<
-        indent() << "fname, mtype, rseqid = @iprot.readMessageBegin()" << endl;
-
       // TODO(mcslee): Validate message reply here, seq ids etc.
 
       f_service_ <<
+        indent() << "fname, mtype, rseqid = @iprot.readMessageBegin()" << endl <<
+        indent() << "if mtype == TMessageType::EXCEPTION" << endl <<
+        indent() << "  x = TApplicationException.new()" << endl <<
+        indent() << "  x.read(@iprot)" << endl <<
+        indent() << "  @iprot.readMessageEnd()" << endl <<
+        indent() << "  raise x" << endl <<
+        indent() << "end" << endl;
+
+      f_service_ <<
         indent() << "result = " << resultname << ".new()" << endl <<
         indent() << "result.read(@iprot)" << endl <<
         indent() << "@iprot.readMessageEnd()" << endl;
@@ -739,7 +745,7 @@
           "return" << endl;
       } else {
         f_service_ <<
-          indent() << "raise StandardError.new('" << (*f_iter)->get_name() << " failed: unknown result')" << endl;
+          indent() << "raise TApplicationException.new(TApplicationException::MISSING_RESULT, '" << (*f_iter)->get_name() << " failed: unknown result')" << endl;
       }     
 
       // Close function
@@ -812,7 +818,14 @@
     indent() << "if (@processMap.has_key?(name))" << endl <<
     indent() << "  @processMap[name].call(seqid, iprot, oprot)" << endl <<
     indent() << "else" << endl <<
-    indent() << "  print \"Unknown function #{name}\"" << endl <<
+    indent() << "  iprot.skip(TType::STRUCT)" << endl <<
+    indent() << "  iprot.readMessageEnd()" << endl <<
+    indent() << "  x = TApplicationException.new(TApplicationException::UNKNOWN_METHOD, 'Unknown function '+name)" << endl <<
+    indent() << "  oprot.writeMessageBegin(name, TMessageType::EXCEPTION, seqid)" << endl <<
+    indent() << "  x.write(oprot)" << endl <<
+    indent() << "  oprot.writeMessageEnd()" << endl <<
+    indent() << "  oprot.trans.flush()" << endl <<
+    indent() << "  return" << endl <<
     indent() << "end" << endl;
 
   // Read end of args field, the T_STOP, and the struct close