Commits

Ali Gholami Rudi  committed 0fb2ea8

exceptions: added ModuleDecodeError exception

  • Participants
  • Parent commits 70f8c03

Comments (0)

Files changed (3)

File rope/base/exceptions.py

         super(ModuleSyntaxError, self).__init__(
             'Syntax error in file <%s> line <%s>: %s' %
             (filename, lineno, message))
+
+
+class ModuleDecodeError(RopeError):
+    """Cannot decode module"""
+
+    def __init__(self, filename, message):
+        self.filename = filename
+        self.message_ = message
+        super(ModuleDecodeError, self).__init__(
+            'Cannot decode file <%s>: %s' % (filename, message))

File rope/base/resources.py

 
     def read(self):
         data = self.read_bytes()
-        return rope.base.fscommands.file_data_to_unicode(data)
+        try:
+            return rope.base.fscommands.file_data_to_unicode(data)
+        except UnicodeDecodeError, e:
+            raise exceptions.ModuleDecodeError(self.path, e.reason)
 
     def read_bytes(self):
         return open(self.real_path, 'rb').read()

File ropetest/pycoretest.py

         except exceptions.ModuleSyntaxError, e:
             self.assertEquals(1, e.lineno)
 
-    @testutils.assert_raises(UnicodeDecodeError)
+    @testutils.assert_raises(exceptions.ModuleDecodeError)
     def test_not_syntax_errors_when_cannot_decode_file(self):
         mod = testutils.create_module(self.project, 'mod')
         contents = '\nsdsdsd\n\xa9\n'