lib/ernie.rb in ernie-0.3.3 vs lib/ernie.rb in ernie-0.3.4
- old
+ new
@@ -57,10 +57,12 @@
end
def self.dispatch(mod, fun, args)
xargs = deconvert(args)
self.log("-- " + [mod, fun, xargs].inspect)
+ self.mods[mod] || raise(ServerError.new("No such module: '#{mod}'"))
+ self.mods[mod].funs[fun] || raise(ServerError.new("No such function '#{mod}:#{fun}'"))
res = self.mods[mod].funs[fun].call(*xargs)
convert(res)
end
def self.start
@@ -72,12 +74,17 @@
begin
res = self.dispatch(mod, fun, args)
xres = [:reply, res]
self.log("<- " + xres.inspect)
f.send!(xres)
+ rescue ServerError => e
+ xres = [:error, [:server, 0, e.message, e.backtrace]]
+ self.log("<- " + xres.inspect)
+ self.log(e.backtrace.join("\n"))
+ f.send!(xres)
rescue Object => e
- xres = [:error, [:user, 0, e.message]]
+ xres = [:error, [:user, 0, e.message, e.backtrace]]
self.log("<- " + xres.inspect)
self.log(e.backtrace.join("\n"))
f.send!(xres)
end
f.receive_loop
@@ -102,9 +109,11 @@
f.receive_loop
end
end
end
end
+
+class Ernie::ServerError < StandardError; end
class Ernie::Mod
attr_accessor :name, :funs
def initialize(name)
\ No newline at end of file