mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
add DRbRemoteError. [ruby-list:40348], [ruby-list:40390]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7535 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
d4b0bf031d
commit
a402acbbb6
4 changed files with 48 additions and 4 deletions
|
@ -1,3 +1,12 @@
|
|||
Sat Dec 11 21:10:16 2004 Masatoshi SEKI <m_seki@mva.biglobe.ne.jp>
|
||||
|
||||
* lib/drb/drb.rb: add DRbRemoteError. [ruby-list:40348],
|
||||
[ruby-list:40390]
|
||||
|
||||
* test/drb/drbtest.rb: ditto.
|
||||
|
||||
* test/drb/ut_drb.rb: ditto.
|
||||
|
||||
Sat Dec 11 13:08:28 2004 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||
|
||||
* sample/optparse/subcommand.rb: a sample for sub commands like
|
||||
|
|
|
@ -430,6 +430,15 @@ module DRb
|
|||
end
|
||||
end
|
||||
|
||||
class DRbRemoteError < DRbError
|
||||
def initialize(error)
|
||||
@reason = error.class.to_s
|
||||
super("#{error.message} (#{error.class})")
|
||||
set_backtrace(error.backtrace)
|
||||
end
|
||||
attr_reader :reason
|
||||
end
|
||||
|
||||
# Class wrapping a marshalled object whose type is unknown locally.
|
||||
#
|
||||
# If an object is returned by a method invoked over drb, but the
|
||||
|
@ -539,12 +548,12 @@ module DRb
|
|||
@argc_limit = config[:argc_limit]
|
||||
end
|
||||
|
||||
def dump(obj) # :nodoc:
|
||||
obj = DRbObject.new(obj) if obj.kind_of? DRbUndumped
|
||||
def dump(obj, error=false) # :nodoc:
|
||||
obj = make_proxy(obj, error) if obj.kind_of? DRbUndumped
|
||||
begin
|
||||
str = Marshal::dump(obj)
|
||||
rescue
|
||||
str = Marshal::dump(DRbObject.new(obj))
|
||||
str = Marshal::dump(make_proxy(obj, error))
|
||||
end
|
||||
[str.size].pack('N') + str
|
||||
end
|
||||
|
@ -602,7 +611,7 @@ module DRb
|
|||
end
|
||||
|
||||
def send_reply(stream, succ, result) # :nodoc:
|
||||
stream.write(dump(succ) + dump(result))
|
||||
stream.write(dump(succ) + dump(result, !succ))
|
||||
rescue
|
||||
raise(DRbConnError, $!.message, $!.backtrace)
|
||||
end
|
||||
|
@ -612,6 +621,15 @@ module DRb
|
|||
result = load(stream)
|
||||
[succ, result]
|
||||
end
|
||||
|
||||
private
|
||||
def make_proxy(obj, error=false)
|
||||
if error
|
||||
DRbRemoteError.new(obj)
|
||||
else
|
||||
DRbObject.new(obj)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# Module managing the underlying network protocol(s) used by drb.
|
||||
|
|
|
@ -231,6 +231,19 @@ module DRbCore
|
|||
assert_kind_of(DRbObject, v)
|
||||
end
|
||||
end
|
||||
|
||||
def test_11_remote_no_method_error
|
||||
assert_raises(DRb::DRbRemoteError) do
|
||||
@there.remote_no_method_error
|
||||
end
|
||||
begin
|
||||
@there.remote_no_method_error
|
||||
rescue
|
||||
error = $!
|
||||
assert_match(/^undefined method .*\(NoMethodError\)/, error.message)
|
||||
assert_equal('NoMethodError', error.reason)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
module DRbAry
|
||||
|
|
|
@ -66,6 +66,10 @@ class DRbEx
|
|||
raise UError
|
||||
end
|
||||
|
||||
def remote_no_method_error
|
||||
invoke_no_method(self)
|
||||
end
|
||||
|
||||
def test_yield
|
||||
yield
|
||||
yield([])
|
||||
|
|
Loading…
Add table
Reference in a new issue