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

[py] Fix BrowserError issues #12150

Merged
merged 3 commits into from
Jun 14, 2023

Conversation

bastimeyer
Copy link
Contributor

Description

This fixes two issues with selenium.webdriver.common.bidi.cdp.BrowserError:

  1. A KeyError can get raised when creating a new BrowserError instance when the passed obj dict/mapping doesn't have the code or message keys.
  2. When the browser has sent an invalid session ID, a string incorrectly gets passed to the BrowserError constructor, which would make it raise a TypeError.

Motivation and Context

  1. I noticed that issue while experimenting with Firefox's CDP v85 implementation. Apparently FF doesn't properly support devtools.fetch.enable and it returns a response with the error key (error message irrelevant):
    if "error" in data:
    # If the server reported an error, convert it to an exception and do
    # not process the response any further.
    self.inflight_result[cmd_id] = BrowserError(data["error"])

    That error dict however is missing the code key, hence the KeyError being raised while trying to initialize the exception.
    Since both code and message are now "optional", do you want me to add default values instead, e.g. "unknown"?
  2. Simple error that could've been caught earlier if there were any typing information (which I didn't add). The error code I've added is copied from the error a few lines above. I don't know if that's correct though.
    raise BrowserError({"code": -32700, "message": "Client received invalid JSON", "data": message})

No updated tests, because I couldn't find any tests which affect these parts of the code.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist

  • I have read the contributing document.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have added tests to cover my changes.
  • All new and existing tests passed.

@CLAassistant
Copy link

CLAassistant commented Jun 5, 2023

CLA assistant check
All committers have signed the CLA.

Copy link
Member

@diemol diemol left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you, @bastimeyer!

@diemol diemol merged commit d1f1b6f into SeleniumHQ:trunk Jun 14, 2023
@bastimeyer bastimeyer deleted the py/bidi/cdp/fix-browsererror branch June 14, 2023 13:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants