Commits

Yuya Nishihara committed 055b986

wconfig: translate ParsingError of iniparse to error.ParseError (refs #1512)

Because wconfig is a kind of Mercurial's config object, it should hide
iniparse behavior.

With this change, ParsingError can be caught at global exception handler.

Comments (0)

Files changed (2)

tests/wconfig_test.py

 from nose.tools import *
 from nose.plugins.skip import SkipTest
 from StringIO import StringIO
-from mercurial import config
+from mercurial import config, error
 from tortoisehg.util import wconfig
 
 def setup():
     assert_equals(s, written(c).rstrip())
 
 @with_wconfig
+@raises(error.ParseError)
+def check_read_write_parse_error():
+    c = newwconfig()
+    s = 'bar = baz'  # missing header
+    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

 
 import os
 import cStringIO
-from mercurial import util, config as config_mod
+import ConfigParser
+from mercurial import error, util, config as config_mod
 
 try:
     from iniparse import INIConfig
             raise NotImplementedError("wconfig does not support read() more than once")
 
         def newini(fp=None):
-            # TODO: optionxformvalue isn't used by INIConfig ?
-            return INIConfig(fp=fp, optionxformvalue=None)
+            try:
+                # TODO: optionxformvalue isn't used by INIConfig ?
+                return INIConfig(fp=fp, optionxformvalue=None)
+            except ConfigParser.ParsingError, err:
+                raise error.ParseError(err.message.splitlines()[0],
+                                       '%s:%d' % (err.filename, err.lineno))
 
         if not self._readfiles:
             return newini()