# HG changeset patch # User Matt Mackall # Date 2010-06-05 01:57:26 # Node ID 2123aad24d56fc685769d7255a484998f79195e3 # Parent b901bb751999b0385722c5708a5cf5e6436e251f error: add new ParseError for various parsing errors diff --git a/mercurial/config.py b/mercurial/config.py --- a/mercurial/config.py +++ b/mercurial/config.py @@ -103,10 +103,10 @@ class config(object): 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 @@ class config(object): 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: diff --git a/mercurial/dispatch.py b/mercurial/dispatch.py --- a/mercurial/dispatch.py +++ b/mercurial/dispatch.py @@ -24,8 +24,12 @@ def dispatch(args): 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 @@ def _runcatch(ui, args): 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 diff --git a/mercurial/error.py b/mercurial/error.py --- a/mercurial/error.py +++ b/mercurial/error.py @@ -30,9 +30,15 @@ class LookupError(RevlogError, KeyError) 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 SignalInterrupt(KeyboardInterrupt) class SignatureError(Exception): pass - -class Abort(Exception): - """Raised if a command needs to print an error and exit."""