else\r
@wordcache = Hash.new\r
end\r
- debug "\n\n\nA-Z wordcache: #{@wordcache.inspect}\n\n\n"\r
+ debug "A-Z wordcache: #{@wordcache.pretty_inspect}"\r
\r
@rules = {\r
:italian => {\r
k.to_sym\r
}\r
@command = path.last\r
- debug "Created command #{@command.inspect} with path #{@path.join(', ')}"\r
+ debug "Created command #{@command.inspect} with path #{@path.pretty_inspect}"\r
end\r
\r
# Returs self\r
#\r
def set_default_permission(cmd, val)\r
@default_perm.set_permission(Command.new(cmd), val)\r
- debug "Default permissions now:\n#{@default_perm.inspect}"\r
+ debug "Default permissions now: #{@default_perm.pretty_inspect}"\r
end\r
\r
# default knows everybody\r
def initialize\r
super\r
load_array(:default, true)\r
- debug "initialized auth. Botusers: #{@bot.auth.save_array.inspect}"\r
+ debug "initialized auth. Botusers: #{@bot.auth.save_array.pretty_inspect}"\r
end\r
\r
def save\r
if @bot.auth.changed?\r
@registry[key] = @bot.auth.save_array\r
@bot.auth.reset_changed\r
- debug "saved botusers (#{key}): #{@registry[key].inspect}"\r
+ debug "saved botusers (#{key}): #{@registry[key].pretty_inspect}"\r
end\r
end\r
\r
def load_array(key=:default, forced=false)\r
- debug "loading botusers (#{key}): #{@registry[key].inspect}"\r
+ debug "loading botusers (#{key}): #{@registry[key].pretty_inspect}"\r
@bot.auth.load_array(@registry[key], forced) if @registry.has_key?(key)\r
end\r
\r
begin
require 'net/https'
rescue LoadError => e
- error "Couldn't load 'net/https': #{e.inspect}"
+ error "Couldn't load 'net/https': #{e.pretty_inspect}"
error "Secured HTTP connections will fail"
end
self.revalidate
self.response.raw_body
rescue Exception => e
- error e.message
- error e.backtrace.join("\n")
+ error e
raise e
end
end
begin
cached.revalidate(resp)
rescue Exception => e
- error e.message
- error e.backtrace.join("\n")
+ error e
end
debug "reusing cached"
resp = cached.response
Net::HTTPPartialContent === resp
return resp.body
rescue Exception => e
- error e.message
- error e.backtrace.join("\n")
+ error e
end
return nil
end
Net::HTTPServerError == resp
return resp
rescue Exception => e
- error e.message
- error e.backtrace.join("\n")
+ error e
end
return nil
end
raise 'http error' unless Net::HTTPOK === resp
return resp
rescue Exception => e
- error e.message
- error e.backtrace.join("\n")
+ error e
end
return nil
end
(now - val.last_used > max_last) || (now - val.first_used > max_first)
}
rescue => e
- error "Failed to remove stale cache: #{e.inspect}"
+ error "Failed to remove stale cache: #{e.pretty_inspect}"
end
debug "#{@cache.size} pages after"
end
$stderr.reopen($stdout)
exec(command, *args)
rescue Exception => e
- puts "exec of #{command} led to exception: #{e.inspect}"
+ puts "exec of #{command} led to exception: #{e.pretty_inspect}"
Kernel::exit! 0
end
puts "exec of #{command} failed"
begin
require 'bdb'
rescue Exception => e
- error "Got exception: "+e
+ error "Got exception: #{e.pretty_inspect}"
error "rbot couldn't load the bdb module, perhaps you need to install it? try: http://www.ruby-lang.org/en/raa-list.rhtml?name=bdb"
exit 2
end
@@env = BDB::Env.open("#{@bot.botclass}", BDB::INIT_TRANSACTION | BDB::CREATE | BDB::RECOVER, "set_lg_max" => @@lg_max)
debug "DBTree: environment opened with max log size #{@@env.conf['lg_max']}"
rescue => e
- debug "DBTree: failed to open environment: #{e}. Retrying ..."
+ debug "DBTree: failed to open environment: #{e.pretty_inspect}. Retrying ..."
@@env = BDB::Env.open("#{@bot.botclass}", BDB::INIT_TRANSACTION | BDB::CREATE | BDB::RECOVER)
end
#@@env = BDB::Env.open("#{@bot.botclass}", BDB::CREATE | BDB::INIT_MPOOL | BDB::RECOVER)
begin
debug "DBTree: checkpointing ..."
@@env.checkpoint
- rescue => e
- debug "Failed: #{e}"
+ rescue Excpetion => e
+ debug "Failed: #{e.pretty_inspect}"
end
begin
debug "DBTree: flushing log ..."
logs.each { |log|
File.delete(log)
}
- rescue => e
- debug "Failed: #{e}"
+ rescue Exception => e
+ debug "Failed: #{e.pretty_inspect}"
end
end
debug "DBTree: cleaning up environment in #{path}"
BDB::Env.remove("#{path}")
end
- rescue => e
- error "failed to clean up environment: #{e.inspect}"
+ rescue Exception => e
+ error "failed to clean up environment: #{e.pretty_inspect}"
end
end
$logger.level = $cl_loglevel if $cl_loglevel
$logger.level = 0 if $debug
+require 'pp'
+
+class Exception
+ def pretty_print(q)
+ q.group(1, "#<%s: %s" % [self.class, self.message], ">") {
+ q.seplist(self.backtrace, lambda { "\n" }) { |v| v } if self.backtrace
+ }
+ end
+end
+
def rawlog(level, message=nil, who_pos=1)
call_stack = caller
if call_stack.length > who_pos
# Output each line. To distinguish between separate messages and multi-line
# messages originating at the same time, we blank #{who} after the first message
# is output.
- message.to_s.each_line { |l|
+ # Also, we output strings as-is but for other objects we use pretty_inspect
+ case message
+ when String
+ str = message
+ else
+ str = message.pretty_inspect
+ end
+ str.each_line { |l|
$logger.add(level, l.chomp, who)
who.gsub!(/./," ")
}
begin
@config = BotConfig.configmanager
@config.bot_associate(self)
- rescue => e
- fatal e.inspect
- fatal e.backtrace.join("\n")
+ rescue Exception => e
+ fatal e
log_session_end
exit 2
end
exit if fork
rescue NotImplementedError
warning "Could not background, fork not supported"
- rescue => e
- warning "Could not background. #{e.inspect}"
+ rescue SystemExit
+ exit 0
+ rescue Exception => e
+ warning "Could not background. #{e.pretty_inspect}"
end
Dir.chdir botclass
# File.umask 0000 # Ensure sensible umask. Adjust as needed.
@auth = Auth::authmanager
@auth.bot_associate(self)
# @auth.load("#{botclass}/botusers.yaml")
- rescue => e
- fatal e.inspect
- fatal e.backtrace.join("\n")
+ rescue Exception => e
+ fatal e
log_session_end
exit 2
end
trap("SIGTERM") { got_sig("SIGTERM") }
trap("SIGHUP") { got_sig("SIGHUP") }
rescue ArgumentError => e
- debug "failed to trap signals (#{e.inspect}): running on Windows?"
- rescue => e
- debug "failed to trap signals: #{e.inspect}"
+ debug "failed to trap signals (#{e.pretty_inspect}): running on Windows?"
+ rescue Exception => e
+ debug "failed to trap signals: #{e.pretty_inspect}"
end
begin
quit if $interrupted > 0
log_session_end
exit 0
rescue Errno::ETIMEDOUT, Errno::ECONNABORTED, TimeoutError, SocketError => e
- error "network exception: #{e.class}: #{e}"
- debug e.backtrace.join("\n")
+ error "network exception: #{e.pretty_inspect}"
quit_msg = e.to_s
rescue BDB::Fatal => e
- fatal "fatal bdb error: #{e.class}: #{e}"
- fatal e.backtrace.join("\n")
+ fatal "fatal bdb error: #{e.pretty_inspect}"
DBTree.stats
# Why restart? DB problems are serious stuff ...
# restart("Oops, we seem to have registry problems ...")
log_session_end
exit 2
rescue Exception => e
- error "non-net exception: #{e.class}: #{e}"
- error e.backtrace.join("\n")
+ error "non-net exception: #{e.pretty_inspect}"
quit_msg = e.to_s
rescue => e
- fatal "unexpected exception: #{e.class}: #{e}"
- fatal e.backtrace.join("\n")
+ fatal "unexpected exception: #{e.pretty_inspect}"
log_session_end
exit 2
end
end
end
- def handle_socket_error(string, err)
- error "#{string} failed: #{err.inspect}"
- debug err.backtrace.join("\n")
+ def handle_socket_error(string, e)
+ error "#{string} failed: #{e.pretty_inspect}"
# We assume that an error means that there are connection
# problems and that we should reconnect, so we
shutdown
- raise SocketError.new(err.inspect)
+ raise SocketError.new(e.inspect)
end
# get the next line from the server (blocks)
reply.strip! if reply
debug "RECV: #{reply.inspect}"
return reply
- rescue => e
+ rescue Exception => e
handle_socket_error(:RECV, e)
end
end
if @sendq.empty?
@timer.stop
end
- rescue => e
- error "Spooling failed: #{e.inspect}"
- error e.backtrace.join("\n")
+ rescue Exception => e
+ error "Spooling failed: #{e.pretty_inspect}"
end
end
end
return unless connected?
begin
@sock.close
- rescue => err
- error "error while shutting down: #{err.inspect}"
- debug err.backtrace.join("\n")
+ rescue Exception => e
+ error "error while shutting down: #{e.pretty_inspect}"
end
@rawsock = nil if @ssl
@sock = nil
@lines_sent += 1
@burst += 1
end
- rescue => e
+ rescue Exception => e
handle_socket_error(:SEND, e)
end
end
else
reg = nil
end
- "<#{self.class.to_s}%s%s%s%s>" % [name, mul, opt, reg]
+ "<%s %s%s%s%s>" % [self.class, name, mul, opt, reg]
end
end
Marshal.restore(val)
rescue Exception => e
error "failed to restore marshal data for #{val.inspect}, attempting recovery or fallback to default"
- debug e.inspect
- debug e.backtrace.join("\n")
+ debug e
if @recovery
begin
return @recovery.call(val)
rescue Exception => ee
error "marshal recovery failed, trying default"
- debug ee.inspect
- debug ee.backtrace.join("\n")
+ debug ee
end
end
unless @default.nil?
else
@func.call
end
- rescue => e
- error "Timer action #{self.inspect} with function #{@func.inspect} failed with error #{e.inspect}"
- error e.backtrace.join("\n")
+ rescue Exception => e
+ error "Timer action #{self.inspect} with function #{@func.inspect} failed!"
+ error e.pretty_inspect
# TODO maybe we want to block this Action?
end
return @once