config: raise ConfigError on non-existing include files stable
authorMartin Geisler <mg@lazybytes.net>
Sat, 12 Dec 2009 16:46:16 +0100
branchstable
changeset 10042 7cdd2a7db2c2
parent 10025 fb45c1e4396f
child 10044 dc5462d94a72
child 10047 27267b1f68b4
config: raise ConfigError on non-existing include files Before, an %include directive for a non-existing file resulted in an IOError and a traceback.
mercurial/config.py
tests/test-hgrc
tests/test-hgrc.out
--- a/mercurial/config.py	Thu Dec 10 12:31:21 2009 +0100
+++ b/mercurial/config.py	Sat Dec 12 16:46:16 2009 +0100
@@ -100,7 +100,13 @@
                 base = os.path.dirname(src)
                 inc = os.path.normpath(os.path.join(base, inc))
                 if include:
-                    include(inc, remap=remap, sections=sections)
+                    try:
+                        include(inc, remap=remap, sections=sections)
+                    except IOError, inst:
+                        msg = _("config error at %s:%d: "
+                                "cannot include %s (%s)") \
+                            % (src, line, inc, inst.strerror)
+                        raise error.ConfigError(msg)
                 continue
             if emptyre.match(l):
                 continue
--- a/tests/test-hgrc	Thu Dec 10 12:31:21 2009 +0100
+++ b/tests/test-hgrc	Sat Dec 12 16:46:16 2009 +0100
@@ -22,3 +22,6 @@
 echo '[foo]' >> $HGRCPATH
 echo '  x = y' >> $HGRCPATH
 hg version 2>&1 | sed -e "s|$HGRCPATH|\$HGRCPATH|"
+
+echo '%include /no-such-file' > $HGRCPATH
+hg version 2>&1 | sed -e "s|$HGRCPATH|\$HGRCPATH|"
--- a/tests/test-hgrc.out	Thu Dec 10 12:31:21 2009 +0100
+++ b/tests/test-hgrc.out	Sat Dec 12 16:46:16 2009 +0100
@@ -11,3 +11,4 @@
 paths.default=.../foo%bar
 ui.slash=True
 hg: config error at $HGRCPATH:8: '  x = y'
+hg: config error at $HGRCPATH:1: cannot include /no-such-file (No such file or directory)