diff options
| author | Ian Cordasco <graffatcolmingov@gmail.com> | 2016-08-06 07:44:09 -0500 |
|---|---|---|
| committer | Ian Cordasco <graffatcolmingov@gmail.com> | 2016-08-06 07:44:20 -0500 |
| commit | 78100de8c6f868313e0b6b06c13a26d3ac2f5b7e (patch) | |
| tree | 93decd0362e6dc0e129776cd86af81087668dcc0 /src/flake8 | |
| parent | 7730a790f47e1cbff9a334891dcbe7efd327010d (diff) | |
| download | flake8-78100de8c6f868313e0b6b06c13a26d3ac2f5b7e.tar.gz | |
Handle SyntaxErrors when tokenizing a file
Closes #205
Diffstat (limited to 'src/flake8')
| -rw-r--r-- | src/flake8/exceptions.py | 5 | ||||
| -rw-r--r-- | src/flake8/processor.py | 8 |
2 files changed, 5 insertions, 8 deletions
diff --git a/src/flake8/exceptions.py b/src/flake8/exceptions.py index 349d471..cf8aae3 100644 --- a/src/flake8/exceptions.py +++ b/src/flake8/exceptions.py @@ -38,7 +38,10 @@ class InvalidSyntax(Flake8Exception): """Initialize our InvalidSyntax exception.""" exception = kwargs.pop('exception', None) self.original_exception = exception - self.error_message = str(exception) + self.error_message = '{0}: {1}'.format( + exception.__class__.__name__, + exception.args[0], + ) self.error_code = 'E902' self.line_number = 1 self.column_number = 0 diff --git a/src/flake8/processor.py b/src/flake8/processor.py index e9d1b8a..44024e5 100644 --- a/src/flake8/processor.py +++ b/src/flake8/processor.py @@ -240,13 +240,7 @@ class FileProcessor(object): break self.tokens.append(token) yield token - # NOTE(sigmavirus24): pycodestyle was catching both a SyntaxError - # and a tokenize.TokenError. In looking a the source on Python 2 and - # Python 3, the SyntaxError should never arise from generate_tokens. - # If we were using tokenize.tokenize, we would have to catch that. Of - # course, I'm going to be unsurprised to be proven wrong at a later - # date. - except tokenize.TokenError as exc: + except (tokenize.TokenError, SyntaxError) as exc: raise exceptions.InvalidSyntax(exception=exc) def line_for(self, line_number): |
