diff options
-rw-r--r-- | lib/rbot/registry.rb | 17 |
1 files changed, 15 insertions, 2 deletions
diff --git a/lib/rbot/registry.rb b/lib/rbot/registry.rb index 4cb1c53f..749f1830 100644 --- a/lib/rbot/registry.rb +++ b/lib/rbot/registry.rb @@ -118,6 +118,9 @@ module Irc # (derived from the plugin's class name, so change it and lose your data). # Calls to registry.each etc, will only iterate over your namespace. class BotRegistryAccessor + + attr_accessor :recovery + # plugins don't call this - a BotRegistryAccessor is created for them and # is accessible via @registry. def initialize(bot, name) @@ -133,6 +136,7 @@ module Irc } @registry = nil @default = nil + @recover = nil # debug "initializing registry accessor with name #{@name}" end @@ -175,10 +179,19 @@ module Irc begin Marshal.restore(val) rescue Exception => e - warning "failed to restore marshal data for #{val.inspect}, falling back to default" + error "failed to restore marshal data for #{val.inspect}, attempting recovery or fallback to default" debug e.inspect debug e.backtrace.join("\n") - if @default != nil + if @recovery + begin + return @recovery.call(val) + rescue Exception => ee + error "marshal recovery failed, trying default" + debug ee.inspect + debug ee.backtrace.join("\n") + end + end + unless @default.nil? begin return Marshal.restore(@default) rescue |