Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[rb] Add backtrace locations and cause to errors #14170

Merged
merged 42 commits into from
Jul 16, 2024
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
3ff3559
Add backtrace locations and cause to errors
aguspe Jun 22, 2024
eb6aa00
Merge branch 'trunk' into fix_backtrace_location
aguspe Jun 22, 2024
ec6f5bc
Add type support and save value to variable
aguspe Jun 22, 2024
6540f73
Merge branch 'fix_backtrace_location' of github.com:aguspe/selenium i…
aguspe Jun 22, 2024
777a8a6
Merge branch 'trunk' into fix_backtrace_location
aguspe Jun 22, 2024
6883b0a
Merge branch 'trunk' into fix_backtrace_location
aguspe Jun 22, 2024
6a76481
Merge branch 'trunk' into fix_backtrace_location
aguspe Jun 22, 2024
0447c6d
Merge branch 'trunk' into fix_backtrace_location
aguspe Jun 23, 2024
4aae5a3
Merge branch 'trunk' into fix_backtrace_location
aguspe Jun 24, 2024
7e4a2cf
Merge branch 'trunk' into fix_backtrace_location
aguspe Jun 24, 2024
3c7b386
Merge branch 'trunk' into fix_backtrace_location
aguspe Jun 24, 2024
c4e2593
Resolve conflicts and update the error class
aguspe Jun 25, 2024
de16eec
Merge branch 'trunk' into fix_backtrace_location
aguspe Jun 26, 2024
4afe312
Merge branch 'trunk' into fix_backtrace_location
aguspe Jun 26, 2024
33bd311
Update implementation
aguspe Jun 26, 2024
48cb412
Merge branch 'fix_backtrace_location' of github.com:aguspe/selenium i…
aguspe Jun 26, 2024
10791b2
Merge branch 'trunk' into fix_backtrace_location
aguspe Jun 26, 2024
5139bbf
Remove unused methods
aguspe Jun 26, 2024
d798475
Merge branch 'fix_backtrace_location' of github.com:aguspe/selenium i…
aguspe Jun 26, 2024
2996653
Error has cause, backtrace and backtrace locations
aguspe Jun 27, 2024
05cfce6
Merge branch 'trunk' into fix_backtrace_location
aguspe Jun 27, 2024
ada5081
Remove english
aguspe Jun 27, 2024
7529157
Merge branch 'fix_backtrace_location' of github.com:aguspe/selenium i…
aguspe Jun 27, 2024
3c64035
Remove unnecessary attributes
aguspe Jun 27, 2024
5c9808a
Return ex
aguspe Jun 27, 2024
176286c
Fix line issue
aguspe Jun 27, 2024
48a7105
Add backtrace back
aguspe Jun 27, 2024
ef832d5
Fix types
aguspe Jun 27, 2024
1f1dcae
Add caller
aguspe Jun 27, 2024
c36c565
Merge branch 'trunk' into fix_backtrace_location
aguspe Jun 28, 2024
7497293
Address review comment
aguspe Jun 28, 2024
2f8b9f7
Include backtrace on the cause
aguspe Jun 29, 2024
a506504
Update types
aguspe Jun 29, 2024
c7bc5d2
Merge branch 'trunk' into fix_backtrace_location
aguspe Jul 5, 2024
32536f5
Merge branch 'trunk' into fix_backtrace_location
aguspe Jul 7, 2024
eb0248e
Merge branch 'trunk' into fix_backtrace_location
aguspe Jul 11, 2024
9ff8252
Merge branch 'trunk' into fix_backtrace_location
aguspe Jul 12, 2024
ea9f4b4
Merge branch 'trunk' into fix_backtrace_location
aguspe Jul 13, 2024
ac8e22a
Improve error types
aguspe Jul 13, 2024
bfedee9
Improve error types
aguspe Jul 13, 2024
834a678
Improve add cause
aguspe Jul 16, 2024
0ef5372
Roll back backtrace on message
aguspe Jul 16, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 12 additions & 5 deletions rb/lib/selenium/webdriver/common/error.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
# specific language governing permissions and limitations
# under the License.

require 'English'
module Selenium
module WebDriver
module Error
Expand Down Expand Up @@ -45,11 +46,21 @@ def self.for_error(error)
}.freeze

class WebDriverError < StandardError
attr_writer :backtrace_locations, :cause

def initialize(msg = '')
# Remove this conditional when all the error pages have been documented
super(URLS[class_name] ? "#{msg}; #{SUPPORT_MSG} #{URLS[class_name]}" : msg)
end

def backtrace_locations
@backtrace_locations ||= Thread.current.backtrace_locations
end

def cause
@cause ||= $ERROR_INFO
end

def class_name
self.class.name&.split('::')&.last&.to_sym
end
Expand Down Expand Up @@ -77,11 +88,7 @@ class UnknownCommandError < WebDriverError; end
# A command failed because the referenced element is no longer attached to the DOM.
#

class StaleElementReferenceError < WebDriverError
def initialize(msg = '')
super("#{msg}; #{SUPPORT_MSG} #{URLS[:StaleElementReferenceError]}")
end
end
class StaleElementReferenceError < WebDriverError; end
aguspe marked this conversation as resolved.
Show resolved Hide resolved

#
# A command failed because the referenced shadow root is no longer attached to the DOM.
Expand Down
6 changes: 6 additions & 0 deletions rb/sig/lib/selenium/webdriver/common/error.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@ module Selenium
URLS: Hash[Symbol, String]

class WebDriverError < StandardError
@backtrace_locations: Array[Thread::Backtrace::Location]?
@cause: Exception?

attr_writer backtrace_locations: Array[Thread::Backtrace::Location]?
attr_writer cause: Exception?
aguspe marked this conversation as resolved.
Show resolved Hide resolved

def class_name: -> Symbol?
end

Expand Down
12 changes: 12 additions & 0 deletions rb/spec/integration/selenium/webdriver/error_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,18 @@ module WebDriver
driver.find_element(id: 'nonexistent')
}.to raise_error(WebDriver::Error::NoSuchElementError, /#no-such-element-exception/)
end

it 'has backtrace locations' do
driver.find_element(id: 'nonexistent')
rescue WebDriver::Error::NoSuchElementError => e
expect(e.backtrace_locations).not_to be_empty
end

it 'has cause' do
driver.find_element(id: 'nonexistent')
rescue WebDriver::Error::NoSuchElementError => e
expect(e.cause).to be_a(WebDriver::Error::NoSuchElementError)
end
end
end # WebDriver
end # Selenium