##// END OF EJS Templates
errors: raise ConfigError on failure to parse config file...
Martin von Zweigbergk -
r46506:9dc1351d default
parent child Browse files
Show More
@@ -274,7 +274,7 b' def parseeol(ui, repo, nodes):'
274 274 return eolfile(ui, repo.root, data)
275 275 except (IOError, LookupError):
276 276 pass
277 except errormod.ParseError as inst:
277 except errormod.ConfigError as inst:
278 278 ui.warn(
279 279 _(
280 280 b"warning: ignoring .hgeol file due to parse error "
@@ -165,7 +165,7 b' class config(object):'
165 165 include(expanded, remap=remap, sections=sections)
166 166 except IOError as inst:
167 167 if inst.errno != errno.ENOENT:
168 raise error.ParseError(
168 raise error.ConfigError(
169 169 _(b"cannot include %s (%s)")
170 170 % (expanded, encoding.strtolocal(inst.strerror)),
171 171 b"%s:%d" % (src, line),
@@ -203,7 +203,7 b' class config(object):'
203 203 message = l.rstrip()
204 204 if l.startswith(b' '):
205 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 208 def read(self, path, fp=None, sections=None, remap=None):
209 209 if not fp:
@@ -227,6 +227,24 b' class HookAbort(Abort):'
227 227 class ConfigError(Abort):
228 228 """Exception raised when parsing config files"""
229 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
247
230 248
231 249 class UpdateAbort(Abort):
232 250 """Raised when an update is aborted for destination issue"""
@@ -466,7 +466,7 b' class ui(object):'
466 466
467 467 try:
468 468 cfg.read(filename, fp, sections=sections, remap=remap)
469 except error.ParseError as inst:
469 except error.ConfigError as inst:
470 470 if trusted:
471 471 raise
472 472 self.warn(
@@ -44,7 +44,7 b' should fail'
44 44 #if no-windows
45 45 $ echo foo > con.xml
46 46 $ hg --config ui.portablefilenames=jump add con.xml
47 abort: ui.portablefilenames value is invalid ('jump')
47 config error: ui.portablefilenames value is invalid ('jump')
48 48 [30]
49 49 $ hg --config ui.portablefilenames=abort add con.xml
50 50 abort: filename contains 'con', which is reserved on Windows: con.xml
@@ -120,8 +120,8 b' on commit:'
120 120 $ hg init sub
121 121 $ echo '= sub' >> .hgsub
122 122 $ hg ci -qAm 'add subrepo ""'
123 hg: parse error at .hgsub:1: = sub
124 [255]
123 config error at .hgsub:1: = sub
124 [30]
125 125
126 126 prepare tampered repo (including the commit above):
127 127
@@ -144,8 +144,8 b' prepare tampered repo (including the com'
144 144 on clone (and update):
145 145
146 146 $ hg clone -q emptypath emptypath2
147 hg: parse error at .hgsub:1: = sub
148 [255]
147 config error at .hgsub:1: = sub
148 [30]
149 149
150 150 Test current path
151 151 -----------------
@@ -7,8 +7,8 b' Invalid syntax: no value'
7 7 > novaluekey
8 8 > EOF
9 9 $ hg showconfig
10 hg: parse error at $TESTTMP/.hg/hgrc:1: novaluekey
11 [255]
10 config error at $TESTTMP/.hg/hgrc:1: novaluekey
11 [30]
12 12
13 13 Invalid syntax: no key
14 14
@@ -16,8 +16,8 b' Invalid syntax: no key'
16 16 > =nokeyvalue
17 17 > EOF
18 18 $ hg showconfig
19 hg: parse error at $TESTTMP/.hg/hgrc:1: =nokeyvalue
20 [255]
19 config error at $TESTTMP/.hg/hgrc:1: =nokeyvalue
20 [30]
21 21
22 22 Test hint about invalid syntax from leading white space
23 23
@@ -25,16 +25,16 b' Test hint about invalid syntax from lead'
25 25 > key=value
26 26 > EOF
27 27 $ hg showconfig
28 hg: parse error at $TESTTMP/.hg/hgrc:1: unexpected leading whitespace: key=value
29 [255]
28 config error at $TESTTMP/.hg/hgrc:1: unexpected leading whitespace: key=value
29 [30]
30 30
31 31 $ cat > .hg/hgrc << EOF
32 32 > [section]
33 33 > key=value
34 34 > EOF
35 35 $ hg showconfig
36 hg: parse error at $TESTTMP/.hg/hgrc:1: unexpected leading whitespace: [section]
37 [255]
36 config error at $TESTTMP/.hg/hgrc:1: unexpected leading whitespace: [section]
37 [30]
38 38
39 39 Reset hgrc
40 40
@@ -332,7 +332,7 b' since bar is not touched in this commit,'
332 332
333 333 input validation
334 334 $ hg convert --config convert.git.similarity=foo --datesort git-repo2 fullrepo
335 abort: convert.git.similarity is not a valid integer ('foo')
335 config error: convert.git.similarity is not a valid integer ('foo')
336 336 [30]
337 337 $ hg convert --config convert.git.similarity=-1 --datesort git-repo2 fullrepo
338 338 abort: similarity must be between 0 and 100
@@ -18,7 +18,7 b''
18 18 Push should provide a hint when both 'default' and 'default-push' not set:
19 19 $ cd c
20 20 $ hg push --config paths.default=
21 abort: default repository not configured!
21 config error: default repository not configured!
22 22 (see 'hg help config.paths')
23 23 [30]
24 24
@@ -91,8 +91,8 b" However, we can't prevent it from loadin"
91 91 $ mkdir -p badrepo/.hg
92 92 $ echo 'invalid-syntax' > badrepo/.hg/hgrc
93 93 $ hg log -b -Rbadrepo default
94 hg: parse error at badrepo/.hg/hgrc:1: invalid-syntax
95 [255]
94 config error at badrepo/.hg/hgrc:1: invalid-syntax
95 [30]
96 96
97 97 $ hg log -b --cwd=inexistent default
98 98 abort: $ENOENT$: 'inexistent'
@@ -16,7 +16,7 b' Basic syntax error'
16 16
17 17 $ echo "invalid" > $HGRC
18 18 $ hg version
19 hg: parse error at $TESTTMP/hgrc:1: invalid
19 config error at $TESTTMP/hgrc:1: invalid
20 20 [255]
21 21 $ echo "" > $HGRC
22 22
@@ -59,7 +59,7 b' Check %include'
59 59 #if unix-permissions no-root
60 60 $ chmod u-r $TESTTMP/included
61 61 $ hg showconfig section
62 hg: parse error at $TESTTMP/hgrc:2: cannot include $TESTTMP/included (Permission denied)
62 config error at $TESTTMP/hgrc:2: cannot include $TESTTMP/included (Permission denied)
63 63 [255]
64 64 #endif
65 65
@@ -68,7 +68,7 b' issue1829: wrong indentation'
68 68 $ echo '[foo]' > $HGRC
69 69 $ echo ' x = y' >> $HGRC
70 70 $ hg version
71 hg: parse error at $TESTTMP/hgrc:2: unexpected leading whitespace: x = y
71 config error at $TESTTMP/hgrc:2: unexpected leading whitespace: x = y
72 72 [255]
73 73
74 74 $ "$PYTHON" -c "from __future__ import print_function; print('[foo]\nbar = a\n b\n c \n de\n fg \nbaz = bif cb \n')" \
@@ -275,7 +275,7 b' Test we can skip the user configuration'
275 275 > EOF
276 276
277 277 $ hg path
278 hg: parse error at $TESTTMP/.hg/hgrc:3: [broken
278 config error at $TESTTMP/.hg/hgrc:3: [broken
279 279 [255]
280 280 $ HGRCSKIPREPO=1 hg path
281 281 foo = $TESTTMP/bar
@@ -283,7 +283,7 b' Test we can skip the user configuration'
283 283 Check that hgweb respect HGRCSKIPREPO=1
284 284
285 285 $ hg serve -n test -p $HGPORT -d --pid-file=hg.pid -A access.log -E errors.log
286 hg: parse error at $TESTTMP/.hg/hgrc:3: [broken
286 config error at $TESTTMP/.hg/hgrc:3: [broken
287 287 [255]
288 288 $ test -f hg.pid && (cat hg.pid >> $DAEMON_PIDS)
289 289 [1]
@@ -302,7 +302,7 b' Check that hgweb respect HGRCSKIPREPO=1'
302 302 Check that zeroconf respect HGRCSKIPREPO=1
303 303
304 304 $ hg paths --config extensions.zeroconf=
305 hg: parse error at $TESTTMP/.hg/hgrc:3: [broken
305 config error at $TESTTMP/.hg/hgrc:3: [broken
306 306 [255]
307 307 $ HGRCSKIPREPO=1 hg paths --config extensions.zeroconf=
308 308 foo = $TESTTMP/bar
@@ -126,7 +126,7 b' Test invalid config default'
126 126 ---------------------------
127 127
128 128 $ hg histedit --config "histedit.defaultrev="
129 abort: config option histedit.defaultrev can't be empty
129 config error: config option histedit.defaultrev can't be empty
130 130 [30]
131 131
132 132 Run on a revision not descendants of the initial parent
@@ -1118,8 +1118,8 b' Bad .hglfs files will block the commit w'
1118 1118
1119 1119 $ echo x > file.txt
1120 1120 $ hg ci -Aqm 'should fail'
1121 hg: parse error at .hglfs:3: bad file ... no commit
1122 [255]
1121 config error at .hglfs:3: bad file ... no commit
1122 [30]
1123 1123
1124 1124 $ cat > .hglfs << EOF
1125 1125 > [track]
@@ -138,7 +138,7 b" symlinks shouldn't be followed"
138 138
139 139 bad config
140 140 $ hg merge 1 --config merge.checkunknown=x
141 abort: merge.checkunknown not valid ('x' is none of 'abort', 'ignore', 'warn')
141 config error: merge.checkunknown not valid ('x' is none of 'abort', 'ignore', 'warn')
142 142 [30]
143 143 this merge should fail
144 144 $ hg merge 1 --config merge.checkunknown=abort
@@ -512,7 +512,7 b' test invalid phase name'
512 512 $ mkcommit I --config phases.new-commit='babar'
513 513 transaction abort!
514 514 rollback completed
515 abort: phases.new-commit: not a valid phase name ('babar')
515 config error: phases.new-commit: not a valid phase name ('babar')
516 516 [30]
517 517 Test phase command
518 518 ===================
@@ -129,8 +129,8 b' Test error cases'
129 129 > revlog.zlib.level=foobar
130 130 > EOF
131 131 $ commitone zlib-level-invalid
132 abort: storage.revlog.zlib.level is not a valid integer ('foobar')
133 abort: storage.revlog.zlib.level is not a valid integer ('foobar')
132 config error: storage.revlog.zlib.level is not a valid integer ('foobar')
133 config error: storage.revlog.zlib.level is not a valid integer ('foobar')
134 134 [30]
135 135
136 136 $ hg init zlib-level-out-of-range
@@ -186,8 +186,8 b' Test error cases'
186 186 > revlog.zstd.level=foobar
187 187 > EOF
188 188 $ commitone zstd-level-invalid
189 abort: storage.revlog.zstd.level is not a valid integer ('foobar')
190 abort: storage.revlog.zstd.level is not a valid integer ('foobar')
189 config error: storage.revlog.zstd.level is not a valid integer ('foobar')
190 config error: storage.revlog.zstd.level is not a valid integer ('foobar')
191 191 [30]
192 192
193 193 $ hg init zstd-level-out-of-range --config format.revlog-compression=zstd
@@ -256,12 +256,12 b' f.close()'
256 256
257 257 try:
258 258 testui(user=b'abc', group=b'def', silent=True)
259 except error.ParseError as inst:
259 except error.ConfigError as inst:
260 260 bprint(inst.format())
261 261
262 262 try:
263 263 testui(debug=True, silent=True)
264 except error.ParseError as inst:
264 except error.ConfigError as inst:
265 265 bprint(inst.format())
266 266
267 267 print()
@@ -176,7 +176,7 b' quux'
176 176 not trusting file .hg/hgrc from untrusted user abc, group def
177 177 ignored .hg/hgrc:1: foo
178 178 # same user, same group
179 hg: parse error at .hg/hgrc:1: foo
179 config error at .hg/hgrc:1: foo
180 180
181 181
182 182 # access typed information
General Comments 0
You need to be logged in to leave comments. Login now