Skip to content

Commit 6d3eb99

Browse files
author
Hendrik Jäger
committed
fix: NameError about unknown exception
TimeoutError used to come from timeout.rb, has been renamed to Timeout::Error, though. In most instances it’s not quite right to use it because timeout.rb is not even loaded in core, only in plugins. So we implement our own errors and exceptions now.
1 parent e7ebf31 commit 6d3eb99

3 files changed

Lines changed: 10 additions & 7 deletions

File tree

data/rbot/plugins/wserver.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ def wserver(m, params)
4444
end
4545
end
4646
end
47-
rescue TimeoutError => e
47+
rescue Timeout::Error => e
4848
m.reply "timed out connecting to #{uri.host}:#{uri.port} :("
4949
rescue RuntimeError => e
5050
redirect_count += 1

lib/rbot/ircbot.rb

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@ class ServerError < RuntimeError
4444
require 'rbot/httputil'
4545

4646
module Irc
47+
Irc::Error = Class.new(RuntimeError)
48+
Irc::PingError = Class.new(Irc::Error)
49+
4750
# Main bot class, which manages the various components, receives messages,
4851
# handles them or passes them to plugins, and contains core functionality.
4952
class Bot
@@ -931,7 +934,7 @@ def mainloop
931934

932935
# Wait for messages and process them as they arrive. If nothing is
933936
# received, we call the ping_server() method that will PING the
934-
# server if appropriate, or raise a TimeoutError if no PONG has been
937+
# server if appropriate, or raise a Irc::PingError if no PONG has been
935938
# received in the user-chosen timeout since the last PING sent.
936939
if @socket.select(1)
937940
break unless reply = @socket.gets
@@ -950,7 +953,7 @@ def mainloop
950953
rescue SystemExit
951954
@keep_looping = false
952955
break
953-
rescue Errno::ETIMEDOUT, Errno::ECONNABORTED, TimeoutError, SocketError => e
956+
rescue Errno::ETIMEDOUT, Errno::ECONNABORTED, Irc::PingError, SocketError => e
954957
error "network exception: #{e.pretty_inspect}"
955958
quit_msg = e.to_s
956959
too_fast += 10 if valid_recv
@@ -1380,7 +1383,7 @@ def ping_server
13801383
if diff > act_timeout
13811384
debug "no PONG from server in #{diff} seconds, reconnecting"
13821385
# the actual reconnect is handled in the main loop:
1383-
raise TimeoutError, "no PONG from server in #{diff} seconds"
1386+
raise Irc::PingError, "no PONG from server in #{diff} seconds"
13841387
end
13851388
end
13861389
end

lib/rbot/plugins.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -625,7 +625,7 @@ def load_botmodule_file(fname, desc=nil)
625625

626626
return :loaded
627627
rescue Exception => err
628-
# rescue TimeoutError, StandardError, NameError, LoadError, SyntaxError => err
628+
# rescue Irc::PingError, StandardError, NameError, LoadError, SyntaxError => err
629629
error report_error("#{desc}#{fname} load failed", err)
630630
bt = err.backtrace.select { |line|
631631
line.match(/^(\(eval\)|#{fname}):\d+/)
@@ -956,7 +956,7 @@ def help(topic = '')
956956
begin
957957
return p.help(key, params)
958958
rescue Exception => err
959-
#rescue TimeoutError, StandardError, NameError, SyntaxError => err
959+
#rescue Irc::PingError, StandardError, NameError, SyntaxError => err
960960
error report_error("#{p.botmodule_class} #{p.name} help() failed:", err)
961961
end
962962
}
@@ -968,7 +968,7 @@ def help(topic = '')
968968
begin
969969
return p.help(key, params)
970970
rescue Exception => err
971-
#rescue TimeoutError, StandardError, NameError, SyntaxError => err
971+
#rescue Irc::PingError, StandardError, NameError, SyntaxError => err
972972
error report_error("#{p.botmodule_class} #{p.name} help() failed:", err)
973973
end
974974
end

0 commit comments

Comments
 (0)