Subject: | Unhelpful messages on errors |
Here's a patch to solve the really unhelpful messages displayed on errors.
Current behaviour:
% test.pl
TApplicationException=HASH(0x2f59760) (in cleanup) Thrift::TException=HASH(0x2f62d50) at /usr/local/perl/5.14.2/site/lib/Thrift/API/HiveClient2/TCLIService.pm line 3236.
Patched:
% perl -IThrift-0.9.0/lib test.pl
TApplicationException error: Required field 'operationHandle' is unset! Struct:TFetchResultsReq(operationHandle:null, orientation:FETCH_NEXT, maxRows:1000000) (code 7)
(in cleanup) Thrift::TException error: TSocket: timed out reading 4 bytes from hiveserver1:10000 (code 0)
Patch:
diff -ru Thrift-0.9.0.orig/lib/Thrift.pm Thrift-0.9.0/lib/Thrift.pm
--- Thrift-0.9.0.orig/lib/Thrift.pm 2013-02-27 19:22:51.000000000 +0100
+++ Thrift-0.9.0/lib/Thrift.pm 2013-07-03 18:04:49.000000000 +0200
@@ -59,6 +59,17 @@
package Thrift::TException;
+# An unclean workaround to have the multiple "die new TException"
+# statements display something useful
+use overload '""' => sub {
+ return
+ ref( $_[0] )
+ . " error: "
+ . ( $_[0]->{message} || 'empty message' )
+ . " (code "
+ . ( defined $_[0]->{code} ? $_[0]->{code} : 'undefined' ) . ")\n";
+};
+
sub new {
my $classname = shift;
my $self = {message => shift, code => shift || 0};