Commits

Yuya Nishihara committed 62bde9c

wconfig: fix AttributeError on translation of pure ParsingError (fixes #3353)

Unlike MissingSectionHeaderError, ParsingError keeps lineno in errors list.

Comments (0)

Files changed (2)

tests/wconfig_test.py

 
 @with_wconfig
 @raises(error.ParseError)
-def check_read_write_parse_error():
+def check_read_write_missing_section_header_error():
     c = newwconfig()
     s = 'bar = baz'  # missing header
     c.read(path='foo', fp=StringIO(s))
     c.write(StringIO())
 
 @with_wconfig
+@raises(error.ParseError)
+def check_read_write_parsing_error():
+    c = newwconfig()
+    s = '[foo]\n:bar = baz'  # Mercurial can parse it but INIConfig can't
+    c.read(path='foo', fp=StringIO(s))
+    c.write(StringIO())
+
+@with_wconfig
 def check_write_after_dict_setitem():
     c = newwconfig({'foo.bar': 'x'})
     c['foo']['bar'] = 'y'

tortoisehg/util/wconfig.py

             try:
                 # TODO: optionxformvalue isn't used by INIConfig ?
                 return INIConfig(fp=fp, optionxformvalue=None)
-            except ConfigParser.ParsingError, err:
+            except ConfigParser.MissingSectionHeaderError, err:
                 raise error.ParseError(err.message.splitlines()[0],
                                        '%s:%d' % (err.filename, err.lineno))
+            except ConfigParser.ParsingError, err:
+                if err.errors:
+                    loc = '%s:%d' % (err.filename, err.errors[0][0])
+                else:
+                    loc = err.filename
+                raise error.ParseError(err.message.splitlines()[0], loc)
 
         if not self._readfiles:
             return newini()