config: catch intended exception when failing to parse config
authorMartin von Zweigbergk <martinvonz@google.com>
Wed, 11 Dec 2019 15:33:07 -0800
changeset 43909 dbaf9aabfb69
parent 43908 4b3c8df189bc
child 43910 c41ed5d4f770
config: catch intended exception when failing to parse config When a new config parser was introduced in fca54469480e (ui: introduce new config parser, 2009-04-23), the reading side would raise a ConfigError which was then caught in the ui code. Then, in 2123aad24d56 (error: add new ParseError for various parsing errors, 2010-06-04), a ParseError was raised instead, but the call site was not updated. Let's start catching that ParseError. We still don't print it in a friendly way, but that's not worse than before. Differential Revision: https://phab.mercurial-scm.org/D7625
mercurial/ui.py
tests/test-trusted.py.out
--- a/mercurial/ui.py	Wed Dec 11 09:39:14 2019 -0800
+++ b/mercurial/ui.py	Wed Dec 11 15:33:07 2019 -0800
@@ -440,7 +440,7 @@
         try:
             cfg.read(filename, fp, sections=sections, remap=remap)
             fp.close()
-        except error.ConfigError as inst:
+        except error.ParseError as inst:
             if trusted:
                 raise
             self.warn(_(b"ignored: %s\n") % stringutil.forcebytestr(inst))
--- a/tests/test-trusted.py.out	Wed Dec 11 09:39:14 2019 -0800
+++ b/tests/test-trusted.py.out	Wed Dec 11 15:33:07 2019 -0800
@@ -174,7 +174,7 @@
 # parse error
 # different user, different group
 not trusting file .hg/hgrc from untrusted user abc, group def
-ParseError('foo', '.hg/hgrc:1')
+ignored: ('foo', '.hg/hgrc:1')
 # same user, same group
 ParseError('foo', '.hg/hgrc:1')