Skip to content

Commit 65ffd18

Browse files
authored
[py] return message as part of exception in execute method (#15751)
1 parent 4768f5a commit 65ffd18

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

py/selenium/webdriver/remote/websocket_connection.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222

2323
from websocket import WebSocketApp # type: ignore
2424

25+
from selenium.common import WebDriverException
26+
2527
logger = logging.getLogger(__name__)
2628

2729

@@ -65,7 +67,12 @@ def execute(self, command):
6567
response = self._messages.pop(current_id)
6668

6769
if "error" in response:
68-
raise Exception(response["error"])
70+
error = response["error"]
71+
if "message" in response:
72+
error_msg = f"{error}: {response['message']}"
73+
raise WebDriverException(error_msg)
74+
else:
75+
raise WebDriverException(error)
6976
else:
7077
result = response["result"]
7178
return self._deserialize_result(result, command)
@@ -97,7 +104,7 @@ def _serialize_command(self, command):
97104
def _deserialize_result(self, result, command):
98105
try:
99106
_ = command.send(result)
100-
raise Exception("The command's generator function did not exit when expected!")
107+
raise WebDriverException("The command's generator function did not exit when expected!")
101108
except StopIteration as exit:
102109
return exit.value
103110

0 commit comments

Comments
 (0)