Commit 0b712334 authored by Yuya Nishihara's avatar Yuya Nishihara

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

Unlike MissingSectionHeaderError, ParsingError keeps lineno in errors list.

--HG--
branch : stable
parent f36d6679d52d
......@@ -226,12 +226,20 @@ def check_read_write():
@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'})
......
......@@ -187,9 +187,15 @@ class _wconfig(object):
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()
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment