Title: [289047] trunk/WebDriverTests
- Revision
- 289047
- Author
- [email protected]
- Date
- 2022-02-03 05:45:11 -0800 (Thu, 03 Feb 2022)
Log Message
Unreviewed. Add another missing file after r288871.
* imported/w3c/tools/webdriver/webdriver/bidi/error.py: Added.
Modified Paths
Added Paths
Diff
Modified: trunk/WebDriverTests/ChangeLog (289046 => 289047)
--- trunk/WebDriverTests/ChangeLog 2022-02-03 13:43:29 UTC (rev 289046)
+++ trunk/WebDriverTests/ChangeLog 2022-02-03 13:45:11 UTC (rev 289047)
@@ -1,5 +1,11 @@
2022-02-03 Carlos Garcia Campos <[email protected]>
+ Unreviewed. Add another missing file after r288871.
+
+ * imported/w3c/tools/webdriver/webdriver/bidi/error.py: Added.
+
+2022-02-03 Carlos Garcia Campos <[email protected]>
+
Unreviewed. Add missing files after r283798.
* imported/selenium/py/selenium/webdriver/common/bidi/__init__.py: Added.
Added: trunk/WebDriverTests/imported/w3c/tools/webdriver/webdriver/bidi/error.py (0 => 289047)
--- trunk/WebDriverTests/imported/w3c/tools/webdriver/webdriver/bidi/error.py (rev 0)
+++ trunk/WebDriverTests/imported/w3c/tools/webdriver/webdriver/bidi/error.py 2022-02-03 13:45:11 UTC (rev 289047)
@@ -0,0 +1,65 @@
+import collections
+
+from typing import ClassVar, DefaultDict, Optional, Type
+
+
+class BidiException(Exception):
+ # The error_code class variable is used to map the JSON Error Code (see
+ # https://w3c.github.io/webdriver/#errors) to a BidiException subclass.
+ # TODO: Match on error and let it be a class variables only.
+ error_code = None # type: ClassVar[str]
+
+ def __init__(self, error: str, message: str, stacktrace: Optional[str]):
+ super(BidiException, self)
+
+ self.error = error
+ self.message = message
+ self.stacktrace = stacktrace
+
+ def __repr__(self):
+ """Return the object representation in string format."""
+ return f"{self.__class__.__name__}({self.error}, {self.message}, {self.stacktrace})"
+
+ def __str__(self):
+ """Return the string representation of the object."""
+ message = f"{self.error} ({self.message})"
+
+ if self.stacktrace:
+ message += f"\n\nRemote-end stacktrace:\n\n{self.stacktrace}"
+
+ return message
+
+
+class InvalidArgumentException(BidiException):
+ error_code = "invalid argument"
+
+
+class UnknownCommandException(BidiException):
+ error_code = "unknown command"
+
+
+class UnknownErrorException(BidiException):
+ error_code = "unknown error"
+
+
+def from_error_details(error: str, message: str, stacktrace: Optional[str]) -> BidiException:
+ """Create specific WebDriver BiDi exception class from error details.
+
+ Defaults to ``UnknownErrorException`` if `error` is unknown.
+ """
+ cls = get(error)
+ return cls(error, message, stacktrace)
+
+
+def get(error_code: str) -> Type[BidiException]:
+ """Get exception from `error_code`.
+
+ It's falling back to ``UnknownErrorException`` if it is not found.
+ """
+ return _errors.get(error_code, UnknownErrorException)
+
+
+_errors: DefaultDict[str, Type[BidiException]] = collections.defaultdict()
+for item in list(locals().values()):
+ if type(item) == type and issubclass(item, BidiException):
+ _errors[item.error_code] = item
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes