diff --git a/ruby/Gemfile.lock b/ruby/Gemfile.lock index 779a090..f346a19 100644 --- a/ruby/Gemfile.lock +++ b/ruby/Gemfile.lock @@ -1,7 +1,7 @@ PATH remote: . specs: - redisrpc (0.3.4) + redisrpc (0.3.5) multi_json (~> 1.3) redis diff --git a/ruby/lib/redisrpc.rb b/ruby/lib/redisrpc.rb index b178ba2..6442929 100644 --- a/ruby/lib/redisrpc.rb +++ b/ruby/lib/redisrpc.rb @@ -20,8 +20,13 @@ module RedisRPC - class RemoteException < Exception; end - class TimeoutException < Exception; end + class RemoteException < RuntimeError + def initialize(message,backtrace=[]) + super(message) + set_backtrace(backtrace) + end + end + class TimeoutException < RuntimeError; end class MalformedResponseException < RemoteException def initialize(response) super "Malformed RPC Response message: #{response.inspect}" @@ -57,7 +62,7 @@ def send( method_name, *args) # response handling rpc_response = MultiJson.load rpc_raw_response - raise RemoteException, rpc_response['exception'] if rpc_response.has_key? 'exception' + raise RemoteException.new(rpc_response['exception'], rpc_response['backtrace']) if rpc_response.has_key? 'exception' raise MalformedResponseException, rpc_response unless rpc_response.has_key? 'return_value' return rpc_response['return_value'] @@ -116,7 +121,10 @@ def run_one return_value = @local_object.send( function_call['name'].to_sym, *function_call['args'] ) rpc_response = {'return_value' => return_value} rescue Object => err - rpc_response = {'exception' => err.to_s, 'backtrace' => err.backtrace} + rpc_response = { + 'exception' => err.to_s, + 'backtrace' => err.backtrace + } end # response tansport diff --git a/ruby/spec/calculator.spec.rb b/ruby/spec/calculator.spec.rb index 167a656..7041052 100644 --- a/ruby/spec/calculator.spec.rb +++ b/ruby/spec/calculator.spec.rb @@ -27,10 +27,23 @@ calculator.val.should == 0.0 end - it 'should raise when missing method is called' do - expect{ calculator.a_missing_method }.to raise_error( - over_redisrpc ? RedisRPC::RemoteException : NoMethodError - ) + context 'when missing method is called' do + subject{ calculator.a_missing_method } + it 'should raise' do + expect{ subject }.to raise_error( + over_redisrpc ? RedisRPC::RemoteException : NoMethodError + ) + end + + it 'should include RedisRPC::Server in backtrace' do + begin + subject + rescue + $!.backtrace.grep(/lib\/redisrpc\.rb:[0-9]+:in `run'/).should_not be_empty + else + fail 'nothing raised' + end + end if over_redisrpc end it 'should raise timeout when execution expires' do