Skip to content

Commit

Permalink
[py] Fix BrowserError issues (#12150)
Browse files Browse the repository at this point in the history
* [py] Fix KeyError on BrowserError

* [py] Fix TypeError on BrowserError

---------

Co-authored-by: Diego Molina <diemol@users.noreply.github.com>
  • Loading branch information
bastimeyer and diemol committed Jun 14, 2023
1 parent 4d70bd8 commit d1f1b6f
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions py/selenium/webdriver/common/bidi/cdp.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,8 +147,8 @@ class BrowserError(Exception):
indicates that an error occurred."""

def __init__(self, obj):
self.code = obj["code"]
self.message = obj["message"]
self.code = obj.get("code")
self.message = obj.get("message")
self.detail = obj.get("data")

def __str__(self):
Expand Down Expand Up @@ -442,7 +442,13 @@ async def _reader_task(self):
try:
session = self.sessions[session_id]
except KeyError:
raise BrowserError(f"Browser sent a message for an invalid session: {session_id!r}")
raise BrowserError(
{
"code": -32700,
"message": "Browser sent a message for an invalid session",
"data": f"{session_id!r}",
}
)
session._handle_data(data)
else:
self._handle_data(data)
Expand Down

0 comments on commit d1f1b6f

Please sign in to comment.