diff options
author | Giuseppe Bilotta <giuseppe.bilotta@gmail.com> | 2006-07-25 01:19:50 +0000 |
---|---|---|
committer | Giuseppe Bilotta <giuseppe.bilotta@gmail.com> | 2006-07-25 01:19:50 +0000 |
commit | 430cdc28d0ae38ddf724889d0f47353715a95249 (patch) | |
tree | 0d534beca388d7a601c052dbe1dc01a65c3d1863 | |
parent | bba93c30e8892bd475427ea211d48f59e4a641aa (diff) |
Inform users about plugins that failed to load; preserve the (supposedly) most interesting part(s) of the backtrace and display them on request
-rw-r--r-- | lib/rbot/plugins.rb | 44 |
1 files changed, 35 insertions, 9 deletions
diff --git a/lib/rbot/plugins.rb b/lib/rbot/plugins.rb index 7b54d1fc..0e9d4cdf 100644 --- a/lib/rbot/plugins.rb +++ b/lib/rbot/plugins.rb @@ -184,10 +184,6 @@ module Plugins def initialize(bot, dirlist) @@bot = bot @dirs = dirlist - @blacklist = Array.new - @@bot.config['plugins.blacklist'].each { |p| - @blacklist << p+".rb" - } scan end @@ -203,6 +199,11 @@ module Plugins # load plugins from pre-assigned list of directories def scan + @blacklist = Array.new + @@bot.config['plugins.blacklist'].each { |p| + @blacklist << p+".rb" + } + @failed = Array.new processed = @blacklist.dup dirs = Array.new dirs << Config::datadir + "/plugins" @@ -232,8 +233,24 @@ module Plugins processed << file rescue Exception => err # rescue TimeoutError, StandardError, NameError, LoadError, SyntaxError => err - warning "plugin #{tmpfilename} load failed: " + err.inspect - warning err.backtrace.join("\n") + warning "plugin #{tmpfilename} load failed\n" + err.inspect + debug err.backtrace.join("\n") + bt = err.backtrace.select { |line| + line.match(/^(\(eval\)|#{tmpfilename}):\d+/) + } + bt.map! { |el| + el.gsub(/^\(eval\)(:\d+)(:in `.*')?(:.*)?/) { |m| + "#{tmpfilename}#{$1}#{$3}" + } + } + msg = err.to_str.gsub(/^\(eval\)(:\d+)(:in `.*')?(:.*)?/) { |m| + "#{tmpfilename}#{$1}#{$3}" + } + newerr = err.class.new(msg) + newerr.set_backtrace(bt) + debug "Simplified error: " << newerr.inspect + debug newerr.backtrace.join("\n") + @failed << { :name => tmpfilename, :err => newerr } end } end @@ -263,11 +280,13 @@ module Plugins # return list of help topics (plugin names) def helptopics if(@@plugins.length > 0) - # return " [plugins: " + @@plugins.keys.sort.join(", ") + "]" - return " [#{length} plugins: " + @@plugins.values.uniq.collect{|p| p.name}.sort.join(", ") + "]" + list = " [#{length} plugin#{'s' if length > 1}: " + @@plugins.values.uniq.collect{|p| p.name}.sort.join(", ") else - return " [no plugins active]" + list = " [no plugins active" end + list << "; #{Reverse}#{@failed.length} plugin#{'s' if @failed.length > 1} failed to load#{Reverse}: use #{Bold}help pluginfailures#{Bold} to see why" unless @failed.empty? + list << "]" + return list end def length @@ -276,6 +295,13 @@ module Plugins # return help for +topic+ (call associated plugin's help method) def help(topic="") + if topic == "pluginfailures" + return "no plugins failed to load" if @failed.empty? + return (@failed.inject([]) { |list, p| + list << "#{Bold}#{p[:name]}#{Bold} failed with #{p[:err].class}: #{p[:err]}" + list << "#{Bold}#{p[:name]}#{Bold} failed at #{p[:err].backtrace.join(', ')}" unless p[:err].backtrace.empty? + }).join("\n") + end if(topic =~ /^(\S+)\s*(.*)$/) key = $1 params = $2 |