Skip to content

Add remote backtrace to RedisRPC::RemoteException #10

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion ruby/Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
redisrpc (0.3.4)
redisrpc (0.3.5)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is an artifact of running rake spec after bumping the version.

multi_json (~> 1.3)
redis

Expand Down
16 changes: 12 additions & 4 deletions ruby/lib/redisrpc.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
Expand Down Expand Up @@ -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']

Expand Down Expand Up @@ -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
Expand Down
21 changes: 17 additions & 4 deletions ruby/spec/calculator.spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down