From 3a6abd145f03aee8bcf1e3aab38f94e80860b18d Mon Sep 17 00:00:00 2001 From: Giuseppe Bilotta Date: Fri, 15 Nov 2013 21:56:34 +0100 Subject: plugins: improve error handling on load Support OAuth2::Error braindead extension to StandardError and wrap loading in an outer rescue to catch problems with the error handling. --- lib/rbot/plugins.rb | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) (limited to 'lib') diff --git a/lib/rbot/plugins.rb b/lib/rbot/plugins.rb index 9a41610f..493f177f 100644 --- a/lib/rbot/plugins.rb +++ b/lib/rbot/plugins.rb @@ -588,7 +588,7 @@ module Plugins } begin newerr = err.class.new(msg) - rescue ArgumentError => err_in_err + rescue ArgumentError => aerr_in_err # Somebody should hang the ActiveSupport developers by their balls # with barbed wire. Their MissingSourceFile extension to LoadError # _expects_ a second argument, breaking the usual Exception interface @@ -601,7 +601,15 @@ module Plugins if err.class.respond_to? :from_message newerr = err.class.from_message(msg) else - raise err_in_err + raise aerr_in_err + end + rescue NoMethodError => nmerr_in_err + # Another braindead extension to StandardError, OAuth2::Error, + # doesn't get a string as message, but a response + if err.respond_to? :response + newerr = err.class.new(err.response) + else + raise nmerr_in_err end end newerr.set_backtrace(bt) @@ -678,7 +686,13 @@ module Plugins end end - did_it = load_botmodule_file("#{dir}/#{file}", "plugin") + begin + did_it = load_botmodule_file("#{dir}/#{file}", "plugin") + rescue Exception => e + error e + did_it = e + end + case did_it when Symbol processed[file.intern] = did_it -- cgit v1.2.3