From: Giuseppe Bilotta Date: Mon, 27 Sep 2010 11:52:14 +0000 (+0200) Subject: * wrap BDB::Fatal classes for abstract trapping X-Git-Url: https://git.netwichtig.de/gitweb/?a=commitdiff_plain;h=2ed8235cdb9e92b0bc46ee97ddbf4c4a1f70c6d8;p=user%2Fhenk%2Fcode%2Fruby%2Frbot.git * wrap BDB::Fatal classes for abstract trapping When using a DB backend different from BDB, the BDB constant may not be defined, causing a NameError during error trapping in the main loop. Fix this by defining our own DBFatal error that maps to BDB::Fatal in the BDB case and is defined as an (unused) Exception for TokyoCabinet. --- diff --git a/lib/rbot/ircbot.rb b/lib/rbot/ircbot.rb index 47d3063c..9b6e2d6a 100644 --- a/lib/rbot/ircbot.rb +++ b/lib/rbot/ircbot.rb @@ -1017,8 +1017,8 @@ class Bot quit_msg = "server ERROR: " + e.message too_fast = e.message.index("reconnect too fast") retry - rescue BDB::Fatal => e - fatal "fatal bdb error: #{e.pretty_inspect}" + rescue DBFatal => e + fatal "fatal db error: #{e.pretty_inspect}" DBTree.stats # Why restart? DB problems are serious stuff ... # restart("Oops, we seem to have registry problems ...") diff --git a/lib/rbot/registry/bdb.rb b/lib/rbot/registry/bdb.rb index 200e38ee..5acfe491 100644 --- a/lib/rbot/registry/bdb.rb +++ b/lib/rbot/registry/bdb.rb @@ -15,6 +15,10 @@ if not defined? BDB exit 2 end +module Irc + DBFatal = BDB::Fatal +end + if BDB::VERSION_MAJOR < 4 fatal "Your bdb (Berkeley DB) version #{BDB::VERSION} is too old!" fatal "rbot will only run with bdb version 4 or higher, please upgrade." diff --git a/lib/rbot/registry/tc.rb b/lib/rbot/registry/tc.rb index eae6e29e..9f410484 100644 --- a/lib/rbot/registry/tc.rb +++ b/lib/rbot/registry/tc.rb @@ -29,6 +29,8 @@ require 'tokyocabinet' module Irc + class DBFatal < Exception ; end + if defined? BDB # DBHash is for tying a hash to disk (using bdb). # Call it with an identifier, for example "mydata". It'll look for