From 2ca8d8af2fac14174d59719cdc6d2c14a10dcc34 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=CE=9D=CE=B9=CE=BA=CF=8C=CE=BB=CE=B1=CE=BF=CF=82-=CE=94?= =?UTF-8?q?=CE=B9=CE=B3=CE=B5=CE=BD=CE=AE=CF=82=20=CE=9A=CE=B1=CF=81=CE=B1?= =?UTF-8?q?=CE=B3=CE=B9=CE=AC=CE=BD=CE=BD=CE=B7=CF=82?= Date: Wed, 30 Mar 2016 16:34:42 +0300 Subject: [PATCH] exception handling was hiding original exception --- parsel/selector.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/parsel/selector.py b/parsel/selector.py index 151553ed..8d8c6939 100644 --- a/parsel/selector.py +++ b/parsel/selector.py @@ -2,6 +2,8 @@ XPath selectors based on lxml """ +import sys + import six from lxml import etree @@ -175,9 +177,10 @@ def xpath(self, query): try: result = xpathev(query, namespaces=self.namespaces, smart_strings=self._lxml_smart_strings) - except etree.XPathError: - msg = u"Invalid XPath: %s" % query - raise ValueError(msg if six.PY3 else msg.encode("unicode_escape")) + except etree.XPathError as exc: + msg = u"XPath error: %s in %s" % (exc, query) + msg = msg if six.PY3 else msg.encode('unicode_escape') + six.reraise(ValueError, ValueError(msg), sys.exc_info()[2]) if type(result) is not list: result = [result]