From 6d3eb99a6213cae314f1d7e24a8ae80c100f0d21 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Hendrik=20J=C3=A4ger?= Date: Wed, 26 Feb 2025 22:33:43 +0100 Subject: [PATCH] fix: NameError about unknown exception MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit 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. --- data/rbot/plugins/wserver.rb | 2 +- lib/rbot/ircbot.rb | 9 ++++++--- lib/rbot/plugins.rb | 6 +++--- 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/data/rbot/plugins/wserver.rb b/data/rbot/plugins/wserver.rb index 2327e337..a68a9d81 100644 --- a/data/rbot/plugins/wserver.rb +++ b/data/rbot/plugins/wserver.rb @@ -44,7 +44,7 @@ class WserverPlugin < Plugin end end end - rescue TimeoutError => e + rescue Timeout::Error => e m.reply "timed out connecting to #{uri.host}:#{uri.port} :(" rescue RuntimeError => e redirect_count += 1 diff --git a/lib/rbot/ircbot.rb b/lib/rbot/ircbot.rb index 35ee7e10..88f89986 100644 --- a/lib/rbot/ircbot.rb +++ b/lib/rbot/ircbot.rb @@ -44,6 +44,9 @@ require 'rbot/language' require 'rbot/httputil' module Irc +Irc::Error = Class.new(RuntimeError) +Irc::PingError = Class.new(Irc::Error) + # Main bot class, which manages the various components, receives messages, # handles them or passes them to plugins, and contains core functionality. class Bot @@ -931,7 +934,7 @@ class Bot # Wait for messages and process them as they arrive. If nothing is # received, we call the ping_server() method that will PING the - # server if appropriate, or raise a TimeoutError if no PONG has been + # server if appropriate, or raise a Irc::PingError if no PONG has been # received in the user-chosen timeout since the last PING sent. if @socket.select(1) break unless reply = @socket.gets @@ -950,7 +953,7 @@ class Bot rescue SystemExit @keep_looping = false break - rescue Errno::ETIMEDOUT, Errno::ECONNABORTED, TimeoutError, SocketError => e + rescue Errno::ETIMEDOUT, Errno::ECONNABORTED, Irc::PingError, SocketError => e error "network exception: #{e.pretty_inspect}" quit_msg = e.to_s too_fast += 10 if valid_recv @@ -1380,7 +1383,7 @@ class Bot if diff > act_timeout debug "no PONG from server in #{diff} seconds, reconnecting" # the actual reconnect is handled in the main loop: - raise TimeoutError, "no PONG from server in #{diff} seconds" + raise Irc::PingError, "no PONG from server in #{diff} seconds" end end end diff --git a/lib/rbot/plugins.rb b/lib/rbot/plugins.rb index 2ed94c3a..a696e351 100644 --- a/lib/rbot/plugins.rb +++ b/lib/rbot/plugins.rb @@ -625,7 +625,7 @@ module Plugins return :loaded rescue Exception => err - # rescue TimeoutError, StandardError, NameError, LoadError, SyntaxError => err + # rescue Irc::PingError, StandardError, NameError, LoadError, SyntaxError => err error report_error("#{desc}#{fname} load failed", err) bt = err.backtrace.select { |line| line.match(/^(\(eval\)|#{fname}):\d+/) @@ -956,7 +956,7 @@ module Plugins begin return p.help(key, params) rescue Exception => err - #rescue TimeoutError, StandardError, NameError, SyntaxError => err + #rescue Irc::PingError, StandardError, NameError, SyntaxError => err error report_error("#{p.botmodule_class} #{p.name} help() failed:", err) end } @@ -968,7 +968,7 @@ module Plugins begin return p.help(key, params) rescue Exception => err - #rescue TimeoutError, StandardError, NameError, SyntaxError => err + #rescue Irc::PingError, StandardError, NameError, SyntaxError => err error report_error("#{p.botmodule_class} #{p.name} help() failed:", err) end end -- 2.32.0.93.g670b81a890