Mercurial > hg
comparison mercurial/config.py @ 45894:9dc1351d0b5f
errors: raise ConfigError on failure to parse config file
This replaces two raises of `ParseError` by `ConfigError`, which makes
it so we get the desired exit code when `ui.detailed-exit-code` is
enabled. Because the exceptions include a location, I had to add that
to `ConfigError` as well. I considered making `ConfigError` a subclass
of `ParseError`, but it doesn't feel like it quite passes the "is-a"
test.
I used "config error: " as prefix for these errors instead of the
previous "hg: parse error: ", which seems a little less accurate now
(and, as I've said before, I don't know what the "hg: " part is
supposed to signify anyway). I can easily be convinced to change the
prefix to something else (including "abort: ").
Some of the exceptions raised here mean that we fail to even load the
`ui` object in the `dispatch` module. When that happens, we don't know
to use detailed exit codes, so some tests (e.g. `test-hgrc.t`) still
see exit code 255. I'll try to get back to that later. It should be
possible to give detailed exit codes if at least part of the config
can be read (e.g. when the system-wide one enables detailed exit codes
and the user's config fails to parse).
Differential Revision: https://phab.mercurial-scm.org/D9355
author | Martin von Zweigbergk <martinvonz@google.com> |
---|---|
date | Fri, 20 Nov 2020 14:43:21 -0800 |
parents | 0883413e09bc |
children | 89a2afe31e82 |
comparison
equal
deleted
inserted
replaced
45893:f4065c3f09b8 | 45894:9dc1351d0b5f |
---|---|
163 expanded = util.expandpath(m.group(1)) | 163 expanded = util.expandpath(m.group(1)) |
164 try: | 164 try: |
165 include(expanded, remap=remap, sections=sections) | 165 include(expanded, remap=remap, sections=sections) |
166 except IOError as inst: | 166 except IOError as inst: |
167 if inst.errno != errno.ENOENT: | 167 if inst.errno != errno.ENOENT: |
168 raise error.ParseError( | 168 raise error.ConfigError( |
169 _(b"cannot include %s (%s)") | 169 _(b"cannot include %s (%s)") |
170 % (expanded, encoding.strtolocal(inst.strerror)), | 170 % (expanded, encoding.strtolocal(inst.strerror)), |
171 b"%s:%d" % (src, line), | 171 b"%s:%d" % (src, line), |
172 ) | 172 ) |
173 continue | 173 continue |
201 continue | 201 continue |
202 | 202 |
203 message = l.rstrip() | 203 message = l.rstrip() |
204 if l.startswith(b' '): | 204 if l.startswith(b' '): |
205 message = b"unexpected leading whitespace: %s" % message | 205 message = b"unexpected leading whitespace: %s" % message |
206 raise error.ParseError(message, (b"%s:%d" % (src, line))) | 206 raise error.ConfigError(message, (b"%s:%d" % (src, line))) |
207 | 207 |
208 def read(self, path, fp=None, sections=None, remap=None): | 208 def read(self, path, fp=None, sections=None, remap=None): |
209 if not fp: | 209 if not fp: |
210 fp = util.posixfile(path, b'rb') | 210 fp = util.posixfile(path, b'rb') |
211 assert getattr(fp, 'mode', 'rb') == 'rb', ( | 211 assert getattr(fp, 'mode', 'rb') == 'rb', ( |