diff options
Diffstat (limited to 'astroid/builder.py')
-rw-r--r-- | astroid/builder.py | 23 |
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: |