Mercurial > public > mercurial-scm > hg
comparison mercurial/error.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 | da178b816812 |
children | 64faa55716f4 |
comparison
equal
deleted
inserted
replaced
45893:f4065c3f09b8 | 45894:9dc1351d0b5f |
---|---|
224 Exists to allow more specialized catching.""" | 224 Exists to allow more specialized catching.""" |
225 | 225 |
226 | 226 |
227 class ConfigError(Abort): | 227 class ConfigError(Abort): |
228 """Exception raised when parsing config files""" | 228 """Exception raised when parsing config files""" |
229 | |
230 def __init__(self, message, location=None, hint=None): | |
231 super(ConfigError, self).__init__(message, hint=hint) | |
232 self.location = location | |
233 | |
234 def format(self): | |
235 from .i18n import _ | |
236 | |
237 if self.location is not None: | |
238 message = _(b"config error at %s: %s\n") % ( | |
239 pycompat.bytestr(self.location), | |
240 self.message, | |
241 ) | |
242 else: | |
243 message = _(b"config error: %s\n") % self.message | |
244 if self.hint: | |
245 message += _(b"(%s)\n") % self.hint | |
246 return message | |
229 | 247 |
230 | 248 |
231 class UpdateAbort(Abort): | 249 class UpdateAbort(Abort): |
232 """Raised when an update is aborted for destination issue""" | 250 """Raised when an update is aborted for destination issue""" |
233 | 251 |