Mercurial > hg
comparison tests/test-config.t @ 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 | 8d72e29ad1e0 |
children | 60523483897c |
comparison
equal
deleted
inserted
replaced
45893:f4065c3f09b8 | 45894:9dc1351d0b5f |
---|---|
5 | 5 |
6 $ cat > .hg/hgrc << EOF | 6 $ cat > .hg/hgrc << EOF |
7 > novaluekey | 7 > novaluekey |
8 > EOF | 8 > EOF |
9 $ hg showconfig | 9 $ hg showconfig |
10 hg: parse error at $TESTTMP/.hg/hgrc:1: novaluekey | 10 config error at $TESTTMP/.hg/hgrc:1: novaluekey |
11 [255] | 11 [30] |
12 | 12 |
13 Invalid syntax: no key | 13 Invalid syntax: no key |
14 | 14 |
15 $ cat > .hg/hgrc << EOF | 15 $ cat > .hg/hgrc << EOF |
16 > =nokeyvalue | 16 > =nokeyvalue |
17 > EOF | 17 > EOF |
18 $ hg showconfig | 18 $ hg showconfig |
19 hg: parse error at $TESTTMP/.hg/hgrc:1: =nokeyvalue | 19 config error at $TESTTMP/.hg/hgrc:1: =nokeyvalue |
20 [255] | 20 [30] |
21 | 21 |
22 Test hint about invalid syntax from leading white space | 22 Test hint about invalid syntax from leading white space |
23 | 23 |
24 $ cat > .hg/hgrc << EOF | 24 $ cat > .hg/hgrc << EOF |
25 > key=value | 25 > key=value |
26 > EOF | 26 > EOF |
27 $ hg showconfig | 27 $ hg showconfig |
28 hg: parse error at $TESTTMP/.hg/hgrc:1: unexpected leading whitespace: key=value | 28 config error at $TESTTMP/.hg/hgrc:1: unexpected leading whitespace: key=value |
29 [255] | 29 [30] |
30 | 30 |
31 $ cat > .hg/hgrc << EOF | 31 $ cat > .hg/hgrc << EOF |
32 > [section] | 32 > [section] |
33 > key=value | 33 > key=value |
34 > EOF | 34 > EOF |
35 $ hg showconfig | 35 $ hg showconfig |
36 hg: parse error at $TESTTMP/.hg/hgrc:1: unexpected leading whitespace: [section] | 36 config error at $TESTTMP/.hg/hgrc:1: unexpected leading whitespace: [section] |
37 [255] | 37 [30] |
38 | 38 |
39 Reset hgrc | 39 Reset hgrc |
40 | 40 |
41 $ echo > .hg/hgrc | 41 $ echo > .hg/hgrc |
42 | 42 |