-
-
Notifications
You must be signed in to change notification settings - Fork 8.6k
Python: phantomjs: fix usage of WebDriverException #475
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
Python: phantomjs: fix usage of WebDriverException #475
Conversation
583170d
to
d873ca1
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, this isn't doing the right thing, but your change isn't either... use the kwargs and call it with WebDriverException(msg="...", stacktrace=traceback.format_exc())
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@lukeis
Thanks for your feedback.
stacktrace
does not appear to be used in other places where the exception is raised?
(neither is msg
being used as kwargs)
I will push a fixup/squash-commit for this though.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it was originally put in there to handle stacktraces that would be returned by the remote end (the browser drivers themselves) and then put into the python Exception.
This is essentially piggy-backing on that 'feature' of the WebDriverException class.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But why does it have to add the traceback to the msg?
It will be available with the exception itself..
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if you raise a new exception here, you will lose the originating traceback. The way as currently coded will show the full traceback when either the user prints it or their test / application quits because they don't handle the exception.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The exception will be from subprocess.Popen
, which is in the same place.
Adding the traceback to the message will it make more noisy (basically duplicating the traceback information).
Use kwargs with WebDriverException, and pass `traceback`, as suggested in SeleniumHQ#475 (comment).
also... have you signed the cla? |
Just did so. |
looks good to merge to me? let me know if you still have hessitations |
In case of an exception from `subprocess.Popen` it would pass the exception as positional argument for `screen`. This fixes it to use the exception in the message.
In case it cannot connect to GhostDriver, it will now also provide information about the port being used.
634d536
to
00b4120
Compare
See my comment above, but I might be missing something. |
So, it needs one more tweak. This gist shows what I was trying to talk about: if we don't include the traceback, we lose the information about the originating exception (the 'as_is.py' one.) While if we include the stacktrace= in it, we'll also get the 'root' cause exception (the 'modified.py' in the gist). |
The only information being "lost" is the difference in the line number, isn't it? |
Ok, that would be different in a real world example. However it still seems unnecessary to me to duplicate the traceback. Maybe (But then this place is still not in line with the other places throwing that exception.) |
Did you test this on Python 3? |
@Dude-x Is there something Python 2/3 specific in there? What's your opinion/feedback on the previous discussion? |
Python 3 actually keeps track of the exception call chain, which is why I asked. If you have tested it in Python 3, then test the response in Python 2. |
You can't pass the exception to `raise` as an argument, you need to to explicitly include it in the string. Signed-off-by: Luke Inman-Semerau <luke.semerau@gmail.com>
In case of an exception from
subprocess.Popen
it would pass theexception as positional argument for
screen
.This fixes it to use the exception in the message.
From https://github.com/SeleniumHQ/selenium/blob/master/py/selenium/common/exceptions.py:
So it seems like it is not used correctly here?!
(Source: https://github.com/SeleniumHQ/selenium/blob/master/py/selenium/webdriver/phantomjs/service.py#L78)
Another commit improves the message when it cannot connect to GhostDriver.