comparison mercurial/config.py @ 45777:0883413e09bc

config: move message about leading spaces in config to config.py When the config parser raises a ParseError, it uses the line that failed to parse as the error message. It doesn't currently tell the user anything about why it failed to parse. b13b99d39a46 (config: highlight parse error caused by leading spaces (issue3214), 2014-03-16) added a checked based on the error *message* having leading spaces. That has worked fine because only the config parser uses the line itself as error message (I think the revset and fileset parsers use more user-friendly proper messages). It still feels like a hack. Let's make the config parser give a useful message about leading whitespace instead. We should ideally follow up with more useful messages for other parse errors in config files. Differential Revision: https://phab.mercurial-scm.org/D9241
author Martin von Zweigbergk <martinvonz@google.com>
date Thu, 22 Oct 2020 10:57:11 -0700
parents 668af67bfd18
children 9dc1351d0b5f
comparison
equal deleted inserted replaced
45776:0fc8b066928a 45777:0883413e09bc
198 self._data[section] = self._data[section].preparewrite() 198 self._data[section] = self._data[section].preparewrite()
199 del self._data[section][name] 199 del self._data[section][name]
200 self._unset.append((section, name)) 200 self._unset.append((section, name))
201 continue 201 continue
202 202
203 raise error.ParseError(l.rstrip(), (b"%s:%d" % (src, line))) 203 message = l.rstrip()
204 if l.startswith(b' '):
205 message = b"unexpected leading whitespace: %s" % message
206 raise error.ParseError(message, (b"%s:%d" % (src, line)))
204 207
205 def read(self, path, fp=None, sections=None, remap=None): 208 def read(self, path, fp=None, sections=None, remap=None):
206 if not fp: 209 if not fp:
207 fp = util.posixfile(path, b'rb') 210 fp = util.posixfile(path, b'rb')
208 assert getattr(fp, 'mode', 'rb') == 'rb', ( 211 assert getattr(fp, 'mode', 'rb') == 'rb', (