Patchwork D7625: config: catch intended exception when failing to parse config

login
register
mail settings
Submitter phabricator
Date Dec. 12, 2019, 11:45 p.m.
Message ID <differential-rev-PHID-DREV-o6ijs5r3aghqqvn6uc63-req@mercurial-scm.org>
Download mbox | patch
Permalink /patch/43770/
State Superseded
Headers show

Comments

phabricator - Dec. 12, 2019, 11:45 p.m.
martinvonz created this revision.
Herald added a subscriber: mercurial-devel.
Herald added a reviewer: hg-reviewers.

REVISION SUMMARY
  When a new config parser was introduced in fca54469480e <https://phab.mercurial-scm.org/rHGfca54469480e0f496556572579d3d2c5d78b2ec9> (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 <https://phab.mercurial-scm.org/rHG2123aad24d56fc685769d7255a484998f79195e3> (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.

REPOSITORY
  rHG Mercurial

BRANCH
  default

REVISION DETAIL
  https://phab.mercurial-scm.org/D7625

AFFECTED FILES
  mercurial/ui.py
  tests/test-trusted.py.out

CHANGE DETAILS




To: martinvonz, #hg-reviewers
Cc: mercurial-devel

Patch

diff --git a/tests/test-trusted.py.out b/tests/test-trusted.py.out
--- a/tests/test-trusted.py.out
+++ b/tests/test-trusted.py.out
@@ -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')
 
diff --git a/mercurial/ui.py b/mercurial/ui.py
--- a/mercurial/ui.py
+++ b/mercurial/ui.py
@@ -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))