Issue41

Title PATCH: fix traceback while parsing config files
Priority bug Status resolved
Superseder Nosy List bos, tksoh
Assigned To tksoh Topics

Created on 2005-10-27.00:13:21 by tksoh, last changed 2005-11-05.05:25:29 by bos.

Messages
msg146 (view) Author: bos Date: 2005-11-05.05:25:29
Looks fixed to me.
msg84 (view) Author: mpm Date: 2005-10-27.20:54:48
Should be fixed in tip
msg81 (view) Author: tonfa Date: 2005-10-27.13:48:04
# HG changeset patch
# User Benoit Boissinot <benoit.boissinot@ens-lyon.org>
# Node ID e09799f2340cbb57e0f7d4713ea8602021619178
# Parent  214f42f23a3bbf04efb96ec1c02097cad11d018d
catch parsing error of config files

diff -r 214f42f23a3b -r e09799f2340c mercurial/ui.py
--- a/mercurial/ui.py	Wed Oct 26 16:32:50 2005 -0700
+++ b/mercurial/ui.py	Thu Oct 27 15:08:35 2005 +0200
@@ -15,7 +15,10 @@
                  interactive=True):
         self.overlay = {}
         self.cdata = ConfigParser.SafeConfigParser()
-        self.cdata.read(util.rcpath)
+        try:
+            self.cdata.read(util.rcpath)
+        except ConfigParser.ParsingError, inst:
+            raise util.Abort(_("Failed to parse %s\n%s") % (util.rcpath, inst))

         self.quiet = self.configbool("ui", "quiet")
         self.verbose = self.configbool("ui", "verbose")
@@ -32,7 +35,14 @@
         self.interactive = (self.interactive and interactive)

     def readconfig(self, fp):
-        self.cdata.readfp(fp)
+        try:
+            self.cdata.readfp(fp)
+        except ConfigParser.ParsingError, inst:
+            try:
+                fn = fp.name
+            except AttributeError:
+                fn = "<??>"
+            raise util.Abort(_("Failed to parse %s\n%s") % (fn, inst))

     def setconfig(self, section, name, val):
         self.overlay[(section, name)] = val
msg73 (view) Author: tksoh Date: 2005-10-27.00:13:20
$ hg status 
Traceback (most recent call last):
  File "/usr/local/bin/hg", line 13, in ?
    commands.run()
  File
"/usr/local/ActivePython-2.4/lib/python2.4/site-packages/mercurial/commands.py",
line 2422, in run
    sys.exit(dispatch(sys.argv[1:]))
  File
"/usr/local/ActivePython-2.4/lib/python2.4/site-packages/mercurial/commands.py",
line 2479, in dispatch
    u = ui.ui()
  File
"/usr/local/ActivePython-2.4/lib/python2.4/site-packages/mercurial/ui.py", line
18, in __init__
    self.cdata.read(util.rcpath)
  File "/usr/local/ActivePython-2.4/lib/python2.4/ConfigParser.py", line 267, in
read
    self._read(fp, filename)
  File "/usr/local/ActivePython-2.4/lib/python2.4/ConfigParser.py", line 490, in
_read
    raise e
ConfigParser.ParsingError: File contains parsing errors: /user/r28629/.hgrc
        [line  8]: 'tip -v\n'
History
Date User Action Args
2005-11-05 05:25:29bossetstatus: testing -> resolved
nosy: + bos
messages: + msg146
2005-10-27 20:54:48mpmsetstatus: chatting -> testing
assignedto: tksoh
messages: + msg84
2005-10-27 13:48:05tonfasetstatus: unread -> chatting
messages: + msg81
title: traceback on broken hgrc -> PATCH: fix traceback while parsing config files
2005-10-27 00:13:21tksohcreate