[rb] raise typed WebDriver errors for BiDi from a generated error-code map - #17855
Conversation
|
Thank you, @titusfortner for this code suggestion. The support packages contain example code that many users find helpful, but they do not necessarily represent After reviewing the change, unless it is a critical fix or a feature that is needed for Selenium We actively encourage people to add the wrapper and helper code that makes sense for them to their own frameworks. |
PR Summary by QodoRaise typed BiDi WebDriver errors via generated error-code map
AI Description
Diagram
High-Level Assessment
Files changed (13)
|
Code Review by Qodo
1.
|
|
Code review by qodo was updated up to the latest commit 056b5d2 |
|
Code review by qodo was updated up to the latest commit 39c008b |
There was a problem hiding this comment.
Pull request overview
This PR updates the Ruby BiDi “generated Protocol” transport to raise typed Selenium::WebDriver::Error subclasses based on the BiDi wire error code, using a generated wire-code → Ruby-class mapping so the set stays in sync with the shared schema.
Changes:
- Generate
BiDi::Protocol::ErrorCode::CLASS_NAMES(wire error code → Ruby exception class name) from the BiDi schema, plus matching RBS signatures. - Register BiDi-only error codes as
Selenium::WebDriver::Error::WebDriverErrorsubclasses while reusing existing classic error classes for shared codes. - Update
BiDi::Transportto raise a typed exception resolved viaProtocol::ErrorCode.for, with unit coverage for shared, BiDi-only, and unknown codes.
Reviewed changes
Copilot reviewed 13 out of 13 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| rb/spec/unit/selenium/webdriver/bidi/transport_spec.rb | Asserts typed exceptions for shared codes, BiDi-only codes, and fallback behavior. |
| rb/sig/lib/selenium/webdriver/bidi/transport.rbs | Updates signature to reflect error_for returning an exception instance. |
| rb/sig/lib/selenium/webdriver/bidi/protocol/error_code.rbs | Adds generated RBS for the ErrorCode map and BiDi-only error subclasses. |
| rb/sig/lib/selenium/webdriver/bidi/error.rbs | Declares the Protocol::ErrorCode.for method for typed error resolution. |
| rb/lib/selenium/webdriver/BUILD.bazel | Wires new templates/data into the generator and verification test. |
| rb/lib/selenium/webdriver/bidi/transport.rb | Raises typed errors via Protocol::ErrorCode.for instead of a generic WebDriverError. |
| rb/lib/selenium/webdriver/bidi/support/templates/error_code.rbs.erb | Template for generated RBS for error-code map + BiDi-only error classes. |
| rb/lib/selenium/webdriver/bidi/support/templates/error_code.rb.erb | Template for generated Ruby error-code map. |
| rb/lib/selenium/webdriver/bidi/support/check_generated.rb | Extends generated-code freshness checks to include error_code.rb. |
| rb/lib/selenium/webdriver/bidi/support/bidi_generate.rb | Adds schema → error-code map generation and emits protocol/error_code.{rb,rbs}. |
| rb/lib/selenium/webdriver/bidi/protocol/error_code.rb | Generated wire-code → Ruby-class mapping. |
| rb/lib/selenium/webdriver/bidi/protocol.rb | Requires classic errors + new BiDi error-code map + BiDi error registrations. |
| rb/lib/selenium/webdriver/bidi/error.rb | Registers BiDi-only error subclasses and implements Protocol::ErrorCode.for. |
|
Code review by qodo was updated up to the latest commit 8ec33ab |
|
Code review by qodo was updated up to the latest commit 9b090ed |
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 13 out of 13 changed files in this pull request and generated no new comments.
Suppressed comments (1)
rb/lib/selenium/webdriver/bidi/transport.rb:48
Transport#error_forcurrently drops the wire error code from the exception message, which makes debugging harder when the code is unrecognized and the class falls back toError::WebDriverError(e.g., the raised message becomes just"gone"). Consider preserving the code at least for the fallback case, and also avoid appending a trailing newline whenstacktraceis empty.
def error_for(reply)
Protocol::ErrorCode.for(reply['error']).new("#{reply['message']}\n#{reply['stacktrace']}")
end
|
Code review by qodo was updated up to the latest commit af56f8d |
🔗 Related Issues
💥 What does this PR do?
WebDriverError.🔧 Implementation Notes
Protocol::ErrorCodemap (wire code → Ruby class name) from the CDDLErrorCodeenum; the generated file is pure data and references nothing else.no such node,no such handle, …) as aWebDriverErrorsubclass inSelenium::WebDriver::Error; codes shared with the classic protocol (no such element,invalid argument, …) reuse the existing classic class, so arescueis identical whether a session ran over BiDi or classic — which matters because the transport is selected silently.Protocol::ErrorCode.for, falling back toWebDriverErrorfor anything outside the closed set.🤖 AI assistance
💡 Additional Considerations
browser/browsing_context/network) still talk raw JSON viasend_cmdand don't yet benefit from the typed errors; migrating them onto the generated Protocol layer is follow-up work.🔄 Types of changes