summaryrefslogtreecommitdiff
path: root/lib/rbot/registry.rb
diff options
context:
space:
mode:
authorGiuseppe Bilotta <giuseppe.bilotta@gmail.com>2007-03-25 04:38:38 +0000
committerGiuseppe Bilotta <giuseppe.bilotta@gmail.com>2007-03-25 04:38:38 +0000
commit734dba499e1dd8822d5e773cb225ae517bd41e8d (patch)
tree8c095775eb4c9b805bc087ccb5a8eeeed6768907 /lib/rbot/registry.rb
parent9b0a12780d2c1eb0ac7be25693eb3873a539a221 (diff)
registry: allow plugins to provide a recovery proc in case data marshalling fails
Diffstat (limited to 'lib/rbot/registry.rb')
-rw-r--r--lib/rbot/registry.rb17
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