mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 969387 - Guard against wrong arguments to MarionetteException. r=mdas
This commit is contained in:
parent
4b1e00cc72
commit
dc7f43c60c
@ -34,9 +34,29 @@ class ErrorCodes(object):
|
||||
MARIONETTE_ERROR = 500
|
||||
|
||||
class MarionetteException(Exception):
|
||||
"""Raised when a generic non-recoverable exception has occured."""
|
||||
|
||||
def __init__(self, message=None,
|
||||
status=ErrorCodes.MARIONETTE_ERROR, cause=None,
|
||||
stacktrace=None):
|
||||
"""Construct new MarionetteException instance.
|
||||
|
||||
:param message: An optional exception message.
|
||||
|
||||
:param status: A WebDriver status code given as an integer.
|
||||
By default the generic Marionette error code 500 will be
|
||||
used.
|
||||
|
||||
:param cause: An optional tuple of three values giving
|
||||
information about the root exception cause. Expected
|
||||
tuple values are (type, value, traceback).
|
||||
|
||||
:param stacktrace: Optional string containing a stacktrace
|
||||
(typically from a failed JavaScript execution) that will
|
||||
be displayed in the exception's string representation.
|
||||
|
||||
"""
|
||||
|
||||
self.msg = message
|
||||
self.status = status
|
||||
self.cause = cause
|
||||
@ -47,11 +67,14 @@ class MarionetteException(Exception):
|
||||
tb = None
|
||||
|
||||
if self.cause:
|
||||
msg += ", caused by %r" % self.cause[0]
|
||||
tb = self.cause[2]
|
||||
if type(self.cause) is tuple:
|
||||
msg += ", caused by %r" % self.cause[0]
|
||||
tb = self.cause[2]
|
||||
else:
|
||||
msg += ", caused by %s" % self.cause
|
||||
if self.stacktrace:
|
||||
stack = "".join(["\t%s\n" % x for x in self.stacktrace.splitlines()])
|
||||
msg += "\nstacktrace:\n%s" % stack
|
||||
st = "".join(["\t%s\n" % x for x in self.stacktrace.splitlines()])
|
||||
msg += "\nstacktrace:\n%s" % st
|
||||
|
||||
return "".join(traceback.format_exception(self.__class__, msg, tb))
|
||||
|
||||
@ -84,8 +107,10 @@ class ScriptTimeoutException(MarionetteException):
|
||||
|
||||
class ElementNotVisibleException(MarionetteException):
|
||||
def __init__(self, message="Element is not currently visible and may not be manipulated",
|
||||
status=ErrorCodes.ELEMENT_NOT_VISIBLE, stacktrace=None):
|
||||
MarionetteException.__init__(self, message, status, stacktrace)
|
||||
status=ErrorCodes.ELEMENT_NOT_VISIBLE,
|
||||
stacktrace=None, cause=None):
|
||||
super(ElementNotVisibleException, self).__init__(
|
||||
message, status=status, cause=cause, stacktrace=stacktrace)
|
||||
|
||||
class NoSuchFrameException(MarionetteException):
|
||||
pass
|
||||
|
@ -39,8 +39,20 @@ class TestMarionetteException(marionette_test.MarionetteTestCase):
|
||||
def test_str(self):
|
||||
exc = errors.MarionetteException(
|
||||
message=message, status=status, cause=cause, stacktrace=stacktrace)
|
||||
s = str(exc)
|
||||
self.assertIn(message, s)
|
||||
self.assertIn(", caused by %r" % cause[0], s)
|
||||
self.assertIn("\nstacktrace:\n\tfirst\n\tsecond\n", s)
|
||||
self.assertIn("MarionetteException:", s)
|
||||
r = str(exc)
|
||||
self.assertIn(message, r)
|
||||
self.assertIn(", caused by %r" % cause[0], r)
|
||||
self.assertIn("\nstacktrace:\n\tfirst\n\tsecond\n", r)
|
||||
self.assertIn("MarionetteException:", r)
|
||||
|
||||
def test_cause_string(self):
|
||||
exc = errors.MarionetteException(cause="foo")
|
||||
self.assertEqual(exc.cause, "foo")
|
||||
r = str(exc)
|
||||
self.assertIn(", caused by foo", r)
|
||||
|
||||
def test_cause_tuple(self):
|
||||
exc = errors.MarionetteException(cause=cause)
|
||||
self.assertEqual(exc.cause, cause)
|
||||
r = str(exc)
|
||||
self.assertIn(", caused by %r" % cause[0], r)
|
||||
|
Loading…
Reference in New Issue
Block a user