changeset 11288:2123aad24d56

error: add new ParseError for various parsing errors
author Matt Mackall <mpm@selenic.com>
date Fri, 04 Jun 2010 20:57:26 -0500
parents b901bb751999
children 4215ce511134
files mercurial/config.py mercurial/dispatch.py mercurial/error.py
diffstat 3 files changed, 25 insertions(+), 14 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/config.py	Fri Jun 04 20:19:53 2010 -0500
+++ b/mercurial/config.py	Fri Jun 04 20:57:26 2010 -0500
@@ -103,10 +103,10 @@
                     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)
+                        raise error.ParseError(
+                            _("cannot include %s (%s)")
+                            % (inc, inst.strerror),
+                            msg, "%s:%s" % (src, line))
                 continue
             if emptyre.match(l):
                 continue
@@ -135,8 +135,7 @@
                     del self._data[section][name]
                 continue
 
-            raise error.ConfigError(_("config error at %s:%d: '%s'")
-                                    % (src, line, l.rstrip()))
+            raise error.ParseError(l.rstrip(), ("%s:%s" % (src, line)))
 
     def read(self, path, fp=None, sections=None, remap=None):
         if not fp:
--- a/mercurial/dispatch.py	Fri Jun 04 20:19:53 2010 -0500
+++ b/mercurial/dispatch.py	Fri Jun 04 20:57:26 2010 -0500
@@ -24,8 +24,12 @@
     except util.Abort, inst:
         sys.stderr.write(_("abort: %s\n") % inst)
         return -1
-    except error.ConfigError, inst:
-        sys.stderr.write(_("hg: %s\n") % inst)
+    except error.ParseError, inst:
+        if len(inst.args) > 1:
+            sys.stderr.write(_("hg: parse error at %s: %s\n") %
+                             (inst.args[1], inst.args[0]))
+        else:
+            sys.stderr.write(_("hg: parse error: %s\n") % ints.args[0])
         return -1
     return _runcatch(u, args)
 
@@ -62,8 +66,13 @@
     except error.AmbiguousCommand, inst:
         ui.warn(_("hg: command '%s' is ambiguous:\n    %s\n") %
                 (inst.args[0], " ".join(inst.args[1])))
-    except error.ConfigError, inst:
-        ui.warn(_("hg: %s\n") % inst.args[0])
+    except error.ParseError, inst:
+        if len(inst.args) > 1:
+            ui.warn(_("hg: parse error at %s: %s\n") %
+                             (inst.args[1], inst.args[0]))
+        else:
+            ui.warn(_("hg: parse error: %s\n") % inst.args[0])
+        return -1
     except error.LockHeld, inst:
         if inst.errno == errno.ETIMEDOUT:
             reason = _('timed out waiting for lock held by %s') % inst.locker
--- a/mercurial/error.py	Fri Jun 04 20:19:53 2010 -0500
+++ b/mercurial/error.py	Fri Jun 04 20:57:26 2010 -0500
@@ -30,9 +30,15 @@
 class CommandError(Exception):
     """Exception raised on errors in parsing the command line."""
 
-class ConfigError(Exception):
+class Abort(Exception):
+    """Raised if a command needs to print an error and exit."""
+
+class ConfigError(Abort):
     'Exception raised when parsing config files'
 
+class ParseError(Abort):
+    'Exception raised when parsing config files (msg[, pos])'
+
 class RepoError(Exception):
     pass
 
@@ -70,6 +76,3 @@
 
 class SignatureError(Exception):
     pass
-
-class Abort(Exception):
-    """Raised if a command needs to print an error and exit."""