From 456fc92bdfaef926767e544adc3353a2828fd1aa Mon Sep 17 00:00:00 2001 From: titusfortner Date: Mon, 20 Oct 2025 20:28:24 -0500 Subject: [PATCH 1/2] [rb] error handling improvements --- rb/lib/selenium/webdriver/bidi.rb | 2 ++ rb/lib/selenium/webdriver/common/network.rb | 13 +++++++------ 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/rb/lib/selenium/webdriver/bidi.rb b/rb/lib/selenium/webdriver/bidi.rb index 80fc5b92fbe22..d372f73d4953b 100644 --- a/rb/lib/selenium/webdriver/bidi.rb +++ b/rb/lib/selenium/webdriver/bidi.rb @@ -61,6 +61,8 @@ def send_cmd(method, **params) raise Error::WebDriverError, error_message(message) if message['error'] message['result'] + rescue StandardError => e + raise Error::WebDriverError, "Unable to send command #{method}: #{e.message}" end def error_message(message) diff --git a/rb/lib/selenium/webdriver/common/network.rb b/rb/lib/selenium/webdriver/common/network.rb index 765ba88097a19..54e342b851556 100644 --- a/rb/lib/selenium/webdriver/common/network.rb +++ b/rb/lib/selenium/webdriver/common/network.rb @@ -45,12 +45,13 @@ def clear_handlers end def add_authentication_handler(username = nil, password = nil, *filter, pattern_type: nil, &block) - selected_block = - if username && password - proc { |auth| auth.authenticate(username, password) } - else - block - end + selected_block = if block_given? + block + elsif !(username && password) + raise ArgumentError, 'Need to provide either a block or both username and password' + else + proc { |auth| auth.authenticate(username, password) } + end add_handler( :auth_required, From 10be9c7f6d564144d883f396e9f8116a93d13274 Mon Sep 17 00:00:00 2001 From: titusfortner Date: Wed, 22 Oct 2025 09:19:27 -0500 Subject: [PATCH 2/2] do not change the error type, just add where issue originates --- rb/lib/selenium/webdriver/bidi.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rb/lib/selenium/webdriver/bidi.rb b/rb/lib/selenium/webdriver/bidi.rb index d372f73d4953b..65e7d1599cb5e 100644 --- a/rb/lib/selenium/webdriver/bidi.rb +++ b/rb/lib/selenium/webdriver/bidi.rb @@ -62,7 +62,7 @@ def send_cmd(method, **params) message['result'] rescue StandardError => e - raise Error::WebDriverError, "Unable to send command #{method}: #{e.message}" + raise e, "Unable to send command #{method}: #{e.message}" end def error_message(message)