summaryrefslogtreecommitdiff
path: root/flake8/exceptions.py
diff options
context:
space:
mode:
authorIan Cordasco <graffatcolmingov@gmail.com>2016-02-26 23:16:25 -0600
committerIan Cordasco <graffatcolmingov@gmail.com>2016-02-26 23:16:33 -0600
commit12e71b037218904b2fdf9ff51c7a0982adde020c (patch)
tree5a31d8f1982d078a168b24a9959841518b4d94b8 /flake8/exceptions.py
parentb12f531da42df816f90f43197aa01d34aefb3d4f (diff)
downloadflake8-12e71b037218904b2fdf9ff51c7a0982adde020c.tar.gz
Incorporate more parsing logic from pycodestyle
Presently we're working on having two singly-responsible classes that will be easy to test and ideally easier to reason about.
Diffstat (limited to 'flake8/exceptions.py')
-rw-r--r--flake8/exceptions.py18
1 files changed, 18 insertions, 0 deletions
diff --git a/flake8/exceptions.py b/flake8/exceptions.py
index ac78769..18ee90c 100644
--- a/flake8/exceptions.py
+++ b/flake8/exceptions.py
@@ -23,3 +23,21 @@ class FailedToLoadPlugin(Flake8Exception):
"""Return a nice string for our exception."""
return self.FORMAT % {'name': self.ep_name,
'exc': self.original_exception}
+
+
+class InvalidSyntax(Flake8Exception):
+ """Exception raised when tokenizing a file fails."""
+
+ def __init__(self, *args, **kwargs):
+ """Initialize our InvalidSyntax exception."""
+ self.original_exception = kwargs.pop('exception')
+ self.error_code = 'E902'
+ self.line_number = 1
+ self.column_number = 0
+ try:
+ self.error_message = self.original_exception.message
+ except AttributeError:
+ # On Python 3, the IOError is an OSError which has a
+ # strerror attribute instead of a message attribute
+ self.error_message = self.original_exception.strerror
+ super(InvalidSyntax, self).__init__(*args, **kwargs)