Patchwork [1,of,9,sethelp] dispatch: consolidate formatting of ParseErrors

login
register
mail settings
Submitter Augie Fackler
Date Feb. 4, 2015, 6:15 p.m.
Message ID <72b6bb087893acf2cd24.1423073706@arthedain.pit.corp.google.com>
Download mbox | patch
Permalink /patch/7659/
State Accepted
Commit 2ee35b6ee4fb2a814824856f094c2184a2982ad5
Headers show

Comments

Augie Fackler - Feb. 4, 2015, 6:15 p.m.
# HG changeset patch
# User Augie Fackler <augie@google.com>
# Date 1422301836 18000
#      Mon Jan 26 14:50:36 2015 -0500
# Node ID 72b6bb087893acf2cd24dc787d9128ac588d5aa6
# Parent  52dff7ef8460fe4cf7f0cd548ba23bd4a127edcb
dispatch: consolidate formatting of ParseErrors

Patch

diff --git a/mercurial/dispatch.py b/mercurial/dispatch.py
--- a/mercurial/dispatch.py
+++ b/mercurial/dispatch.py
@@ -27,6 +27,15 @@  def run():
     "run the command in sys.argv"
     sys.exit((dispatch(request(sys.argv[1:])) or 0) & 255)
 
+def _formatparse(write, inst):
+    if len(inst.args) > 1:
+        write(_("hg: parse error at %s: %s\n") %
+                         (inst.args[1], inst.args[0]))
+        if (inst.args[0][0] == ' '):
+            write(_("unexpected leading whitespace\n"))
+    else:
+        write(_("hg: parse error: %s\n") % inst.args[0])
+
 def dispatch(req):
     "run the command specified in req.args"
     if req.ferr:
@@ -55,13 +64,7 @@  def dispatch(req):
             ferr.write(_("(%s)\n") % inst.hint)
         return -1
     except error.ParseError, inst:
-        if len(inst.args) > 1:
-            ferr.write(_("hg: parse error at %s: %s\n") %
-                             (inst.args[1], inst.args[0]))
-            if (inst.args[0][0] == ' '):
-                ferr.write(_("unexpected leading whitespace\n"))
-        else:
-            ferr.write(_("hg: parse error: %s\n") % inst.args[0])
+        _formatparse(ferr.write, inst)
         return -1
 
     msg = ' '.join(' ' in a and repr(a) or a for a in req.args)
@@ -154,13 +157,7 @@  def _runcatch(req):
         ui.warn(_("hg: command '%s' is ambiguous:\n    %s\n") %
                 (inst.args[0], " ".join(inst.args[1])))
     except error.ParseError, inst:
-        if len(inst.args) > 1:
-            ui.warn(_("hg: parse error at %s: %s\n") %
-                             (inst.args[1], inst.args[0]))
-            if (inst.args[0][0] == ' '):
-                ui.warn(_("unexpected leading whitespace\n"))
-        else:
-            ui.warn(_("hg: parse error: %s\n") % inst.args[0])
+        _formatparse(ui.warn, inst)
         return -1
     except error.LockHeld, inst:
         if inst.errno == errno.ETIMEDOUT: