-
Notifications
You must be signed in to change notification settings - Fork 150
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
[MRG+1] exception handling was hiding original exception #38
Conversation
Current coverage is
|
Yeah, I've been bitten by this in the past, +1. I agree that What do you think of creating a custom error for this?
|
I think it would make sense when parsel becomes an abstract selector library |
Any decisions on this? |
@Digenis , do you have console output example of before and after your change? |
Hey, sorry for the delay! I'm okay with this change -- it's simply adding more information to the exception, which already makes things better. @Digenis not sure if I understand your point about We could also re-raise the exception with the original traceback (which seems a bit tricky to do while being compatible way to both PY2 and PY3). |
@Digenis hey, what about using six.reraise here? |
My suggestion:
This will maintain context both in PY2 and PY3, and will still throw it as ValueError -- thus keeping backwards compatibility with client code already expecting that. |
amended |
After patch
Before patch
|
Looks good to me -- thanks @Digenis ! |
Any xpath error was caught and reraised as a ValueError
complaining about an Invalid XPath,
quoting the original xpath for debugging purposes.
First, "Invalid XPath" is misleading
because the same exception is also raised for xpath evaluation errors.
However it also hides the original exception message
which ends up making xpath debugging harder.
I made it quote the original exception message too
which can be "Unregisted function", "Invalid Expression",
"Undefined namespace prefix" etc.
Now before merging:
Any exception can occur during xpath evaluation
because any python function can be registered and called in an xpath.
I doubt there's anyone wrapping xpath method calls in user code
in another try/except blocks for "ValueError".
Even if somebody actually does this,
I bet it's for logging some custom error message
and this can't justify the usefulness of the current try/except block.
That's why I'm leaning more towards dropping the try/except altogether.
However I opened this PR instead because I doubt you'd accept dropping it.