summaryrefslogtreecommitdiff
path: root/astroid/builder.py
diff options
context:
space:
mode:
authorCeridwen <ceridwenv@gmail.com>2015-09-21 10:47:35 -0400
committerCeridwen <ceridwenv@gmail.com>2015-09-21 10:47:35 -0400
commita1dcb2d18a65be6034459832c91bc5eacbee3c1e (patch)
tree52c6d83a27261bea738b505bd4047d945661e28f /astroid/builder.py
parentaccff12b2d28a3f87d2dc4f5373fb8e1e5de3408 (diff)
downloadastroid-git-a1dcb2d18a65be6034459832c91bc5eacbee3c1e.tar.gz
Use six.reraise to avoid losing tracebacks for simple cases
Diffstat (limited to 'astroid/builder.py')
-rw-r--r--astroid/builder.py23
1 files changed, 16 insertions, 7 deletions
diff --git a/astroid/builder.py b/astroid/builder.py
index fcd9892f..4eefd502 100644
--- a/astroid/builder.py
+++ b/astroid/builder.py
@@ -27,6 +27,8 @@ import os
import sys
import textwrap
+import six
+
from astroid import bases
from astroid import exceptions
from astroid import manager
@@ -53,7 +55,9 @@ if sys.version_info >= (3, 0):
except UnicodeError: # wrong encoding
# detect_encoding returns utf-8 if no encoding specified
msg = 'Wrong (%s) or no encoding specified' % encoding
- raise exceptions.AstroidBuildingException(msg)
+ six.reraise(exceptions.AstroidBuildingException,
+ exceptions.AstroidBuildingException(msg),
+ sys.exc_info()[2])
return stream, encoding, data
else:
@@ -125,11 +129,14 @@ class AstroidBuilder(raw_building.InspectBuilder):
stream, encoding, data = open_source_file(path)
except IOError as exc:
msg = 'Unable to load file %r (%s)' % (path, exc)
- raise exceptions.AstroidBuildingException(msg)
- except SyntaxError as exc: # py3k encoding specification error
- raise exceptions.AstroidBuildingException(exc)
- except LookupError as exc: # unknown encoding
- raise exceptions.AstroidBuildingException(exc)
+ six.reraise(exceptions.AstroidBuildingException,
+ exceptions.AstroidBuildingException(msg),
+ sys.exc_info()[2])
+ except (SyntaxError, LookupError) as exc:
+ # Python 3 encoding specification error or unknown encoding
+ six.reraise(exceptions.AstroidBuildingException,
+ exceptions.AstroidBuildingException(*exc.args),
+ sys.exc_info()[2])
with stream:
# get module name if necessary
if modname is None:
@@ -171,7 +178,9 @@ class AstroidBuilder(raw_building.InspectBuilder):
try:
node = _parse(data + '\n')
except (TypeError, ValueError, SyntaxError) as exc:
- raise exceptions.AstroidBuildingException(exc)
+ six.reraise(exceptions.AstroidBuildingException,
+ exceptions.AstroidBuildingException(*exc.args),
+ sys.exc_info()[2])
if path is not None:
node_file = os.path.abspath(path)
else: