Anonymous avatar Anonymous committed f045e46

Added filename and lineno fields to ModuleSyntaxError

Comments (0)

Files changed (3)

rope/base/exceptions.py

 
 
 class ModuleSyntaxError(RopeError):
-    """Module has syntax errors"""
+    """Module has syntax errors
+
+    The `filename` and `lineno` fields indicate where the error has
+    occurred.
+
+    """
+
+    def __init__(self, filename, lineno, message):
+        self.filename = filename
+        self.lineno = lineno
+        self.message = message
+        super(ModuleSyntaxError, self).__init__(
+            'Syntax error in file <%s> line <%s>: %s' %
+            (filename, lineno, message))

rope/base/pyobjects.py

                 filename = 'string'
                 if resource:
                     filename = resource.path
-                raise exceptions.ModuleSyntaxError(
-                    'Syntax error in file <%s> line <%s>: %s' %
-                    (filename, e.lineno, e.msg))
+                raise exceptions.ModuleSyntaxError(filename, e.lineno, e.msg)
             else:
                 ast_node = ast.parse('\n')
         self.star_imports = []

ropetest/pycoretest.py

     def test_syntax_errors_in_code(self):
         mod = self.pycore.get_string_module('xyx print\n')
 
+    def test_holding_error_location_information(self):
+        try:
+            mod = self.pycore.get_string_module('xyx print\n')
+        except exceptions.ModuleSyntaxError, e:
+            self.assertEquals(1, e.lineno)
+
 
 class PyCoreInProjectsTest(unittest.TestCase):
 
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.