]> git.netwichtig.de Git - user/henk/code/ruby/rbot.git/commitdiff
* wrap BDB::Fatal classes for abstract trapping
authorGiuseppe Bilotta <giuseppe.bilotta@gmail.com>
Mon, 27 Sep 2010 11:52:14 +0000 (13:52 +0200)
committerGiuseppe Bilotta <giuseppe.bilotta@gmail.com>
Mon, 27 Sep 2010 11:52:14 +0000 (13:52 +0200)
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.

lib/rbot/ircbot.rb
lib/rbot/registry/bdb.rb
lib/rbot/registry/tc.rb

index 47d3063c4446764f8f3f17f0b483c9d477414fc9..9b6e2d6a548b6889dbbbafa0a3db9533bcb35328 100644 (file)
@@ -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 ...")
index 200e38ee6532c1d287bc82e5ae82a4be269a6ee5..5acfe4910cd331b17fe7b3b479a121c1cab24678 100644 (file)
@@ -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."
index eae6e29e6a6bd62e195244c2fc922f7a5437b669..9f41048422442128964ab1542af41ffe7f27765c 100644 (file)
@@ -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