Repository navigation
[rb] raise typed WebDriver errors for BiDi from a generated error-code map #17855
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
Merged
titusfortner
merged 6 commits into
SeleniumHQ:trunk
from
titusfortner:rb-bidi-typed-errors
Aug 2, 2026
Merged
Changes from 4 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
91b4086
[rb] raise typed WebDriver errors for BiDi from a generated error-codβ¦
titusfortner 056b5d2
[rb] declare RBS signatures for generated BiDi error classes
titusfortner 39c008b
[rb] declare RBS only for BiDi-only error classes to avoid redeclarinβ¦
titusfortner 8ec33ab
[rb] flag a stale checked-in error_code.rb when the schema has no errβ¦
titusfortner 9b090ed
[rb] remove a stale generated error_code file when the schema has no β¦
titusfortner af56f8d
[rb] drop unreachable empty-schema handling for BiDi error codes
titusfortner File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| # Licensed to the Software Freedom Conservancy (SFC) under one | ||
| # or more contributor license agreements. See the NOTICE file | ||
| # distributed with this work for additional information | ||
| # regarding copyright ownership. The SFC licenses this file | ||
| # to you under the Apache License, Version 2.0 (the | ||
| # "License"); you may not use this file except in compliance | ||
| # with the License. You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, | ||
| # software distributed under the License is distributed on an | ||
| # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| # KIND, either express or implied. See the License for the | ||
| # specific language governing permissions and limitations | ||
| # under the License. | ||
|
|
||
| require 'selenium/webdriver/common/error' | ||
| require 'selenium/webdriver/bidi/protocol/error_code' | ||
|
|
||
| module Selenium | ||
| module WebDriver | ||
| module Error | ||
| # Register each BiDi-only code as a WebDriverError subclass; shared codes keep their classic class. | ||
| BiDi::Protocol::ErrorCode::CLASS_NAMES.each_value do |name| | ||
| const_set(name, Class.new(WebDriverError)) unless const_defined?(name, false) | ||
| end | ||
| end | ||
|
|
||
| class BiDi | ||
| module Protocol | ||
| module ErrorCode | ||
| # The exception class for a wire error code, or WebDriverError for an unknown one. | ||
| def self.for(code) | ||
| name = code && CLASS_NAMES[code] | ||
| name ? Error.const_get(name) : Error::WebDriverError | ||
| end | ||
| end | ||
| end | ||
| end | ||
| end | ||
| end | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,66 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| # Licensed to the Software Freedom Conservancy (SFC) under one | ||
| # or more contributor license agreements. See the NOTICE file | ||
| # distributed with this work for additional information | ||
| # regarding copyright ownership. The SFC licenses this file | ||
| # to you under the Apache License, Version 2.0 (the | ||
| # "License"); you may not use this file except in compliance | ||
| # with the License. You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, | ||
| # software distributed under the License is distributed on an | ||
| # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| # KIND, either express or implied. See the License for the | ||
| # specific language governing permissions and limitations | ||
| # under the License. | ||
|
|
||
| # DO NOT EDIT! This file is generated by rb/lib/selenium/webdriver/bidi/support/bidi_generate.rb. | ||
| # Regenerate with: `bazel run //rb/lib/selenium/webdriver:bidi-generate` | ||
|
|
||
| module Selenium | ||
| module WebDriver | ||
| class BiDi | ||
| module Protocol | ||
| # The BiDi ErrorCode enum: each wire value mapped to its Ruby exception class name. | ||
| # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ | ||
| module ErrorCode | ||
| CLASS_NAMES = { | ||
| 'invalid argument' => 'InvalidArgumentError', | ||
| 'invalid selector' => 'InvalidSelectorError', | ||
| 'invalid session id' => 'InvalidSessionIdError', | ||
| 'invalid web extension' => 'InvalidWebExtensionError', | ||
| 'move target out of bounds' => 'MoveTargetOutOfBoundsError', | ||
| 'no such alert' => 'NoSuchAlertError', | ||
| 'no such network collector' => 'NoSuchNetworkCollectorError', | ||
| 'no such element' => 'NoSuchElementError', | ||
| 'no such frame' => 'NoSuchFrameError', | ||
| 'no such handle' => 'NoSuchHandleError', | ||
| 'no such history entry' => 'NoSuchHistoryEntryError', | ||
| 'no such intercept' => 'NoSuchInterceptError', | ||
| 'no such network data' => 'NoSuchNetworkDataError', | ||
| 'no such node' => 'NoSuchNodeError', | ||
| 'no such request' => 'NoSuchRequestError', | ||
| 'no such screencast' => 'NoSuchScreencastError', | ||
| 'no such script' => 'NoSuchScriptError', | ||
| 'no such storage partition' => 'NoSuchStoragePartitionError', | ||
| 'no such user context' => 'NoSuchUserContextError', | ||
| 'no such web extension' => 'NoSuchWebExtensionError', | ||
| 'session not created' => 'SessionNotCreatedError', | ||
| 'unable to capture screen' => 'UnableToCaptureScreenError', | ||
| 'unable to close browser' => 'UnableToCloseBrowserError', | ||
| 'unable to set cookie' => 'UnableToSetCookieError', | ||
| 'unable to set file input' => 'UnableToSetFileInputError', | ||
| 'unavailable network data' => 'UnavailableNetworkDataError', | ||
| 'underspecified storage partition' => 'UnderspecifiedStoragePartitionError', | ||
| 'unknown command' => 'UnknownCommandError', | ||
| 'unknown error' => 'UnknownError', | ||
| 'unsupported operation' => 'UnsupportedOperationError' | ||
| }.freeze | ||
| end # ErrorCode | ||
| end # Protocol | ||
| end # BiDi | ||
| end # WebDriver | ||
| end # Selenium |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
rb/lib/selenium/webdriver/bidi/support/templates/error_code.rb.erb
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| # Licensed to the Software Freedom Conservancy (SFC) under one | ||
| # or more contributor license agreements. See the NOTICE file | ||
| # distributed with this work for additional information | ||
| # regarding copyright ownership. The SFC licenses this file | ||
| # to you under the Apache License, Version 2.0 (the | ||
| # "License"); you may not use this file except in compliance | ||
| # with the License. You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, | ||
| # software distributed under the License is distributed on an | ||
| # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| # KIND, either express or implied. See the License for the | ||
| # specific language governing permissions and limitations | ||
| # under the License. | ||
|
|
||
| <%= generated_note %> | ||
|
|
||
| module Selenium | ||
| module WebDriver | ||
| class BiDi | ||
| module Protocol | ||
| # The BiDi ErrorCode enum: each wire value mapped to its Ruby exception class name. | ||
| # @see <%= BiDiGenerate::BIDI_DOC_URL %> | ||
| module ErrorCode | ||
| CLASS_NAMES = { | ||
| <%= mod.codes.map { |wire, name| "'#{wire}' => '#{name}'" }.join(",\n ") %> | ||
| }.freeze | ||
| end # ErrorCode | ||
| end # Protocol | ||
| end # BiDi | ||
| end # WebDriver | ||
| end # Selenium |
39 changes: 39 additions & 0 deletions
39
rb/lib/selenium/webdriver/bidi/support/templates/error_code.rbs.erb
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| # Licensed to the Software Freedom Conservancy (SFC) under one | ||
| # or more contributor license agreements. See the NOTICE file | ||
| # distributed with this work for additional information | ||
| # regarding copyright ownership. The SFC licenses this file | ||
| # to you under the Apache License, Version 2.0 (the | ||
| # "License"); you may not use this file except in compliance | ||
| # with the License. You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, | ||
| # software distributed under the License is distributed on an | ||
| # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| # KIND, either express or implied. See the License for the | ||
| # specific language governing permissions and limitations | ||
| # under the License. | ||
|
|
||
| <%= generated_note %> | ||
|
|
||
| module Selenium | ||
| module WebDriver | ||
| class BiDi | ||
| module Protocol | ||
| module ErrorCode | ||
| CLASS_NAMES: Hash[String, String] | ||
| end | ||
| end | ||
| end | ||
|
|
||
| # Signatures for the BiDi-only exception classes bidi/error.rb registers; codes shared with the | ||
| # classic protocol are already declared in common/error.rbs. | ||
| module Error | ||
| <%- mod.new_classes.each do |name| -%> | ||
| class <%= name %> < WebDriverError | ||
| end | ||
| <%- end -%> | ||
| end | ||
| end | ||
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| # Licensed to the Software Freedom Conservancy (SFC) under one | ||
| # or more contributor license agreements. See the NOTICE file | ||
| # distributed with this work for additional information | ||
| # regarding copyright ownership. The SFC licenses this file | ||
| # to you under the Apache License, Version 2.0 (the | ||
| # "License"); you may not use this file except in compliance | ||
| # with the License. You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, | ||
| # software distributed under the License is distributed on an | ||
| # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| # KIND, either express or implied. See the License for the | ||
| # specific language governing permissions and limitations | ||
| # under the License. | ||
|
|
||
| module Selenium | ||
| module WebDriver | ||
| class BiDi | ||
| module Protocol | ||
| module ErrorCode | ||
| def self.for: (String? code) -> singleton(::Selenium::WebDriver::Error::WebDriverError) | ||
|
titusfortner marked this conversation as resolved.
|
||
| end | ||
| end | ||
| end | ||
| end | ||
| end | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.