alias: handle shlex error in command aliases stable
authorYuya Nishihara <yuya@tcha.org>
Sat, 17 May 2014 13:06:16 +0900
branchstable
changeset 21569 c5afb07c33d3
parent 21568 8dd17b19e722
child 21570 d0ec3800101a
alias: handle shlex error in command aliases No command should fail with ValueError just because there is unparseable alias definition. It returns 1 like other badalias handlers, but should be changed to 255 in a later version because we use 255 for general command error.
mercurial/dispatch.py
tests/test-alias.t
--- a/mercurial/dispatch.py	Thu May 08 19:03:00 2014 +0900
+++ b/mercurial/dispatch.py	Sat May 17 13:06:16 2014 +0900
@@ -383,7 +383,16 @@
             self.fn = fn
             return
 
-        args = shlex.split(self.definition)
+        try:
+            args = shlex.split(self.definition)
+        except ValueError, inst:
+            def fn(ui, *args):
+                ui.warn(_("error in definition for alias '%s': %s\n")
+                        % (self.name, inst))
+                return 1
+            self.fn = fn
+            self.badalias = True
+            return
         self.cmdname = cmd = args.pop(0)
         args = map(util.expandpath, args)
 
--- a/tests/test-alias.t	Thu May 08 19:03:00 2014 +0900
+++ b/tests/test-alias.t	Sat May 17 13:06:16 2014 +0900
@@ -11,6 +11,7 @@
   > ambiguous = s
   > recursive = recursive
   > nodefinition =
+  > noclosingquotation = '
   > no--cwd = status --cwd elsewhere
   > no-R = status -R elsewhere
   > no--repo = status --repo elsewhere
@@ -92,6 +93,15 @@
   no definition for alias 'nodefinition'
 
 
+no closing quotation
+
+  $ hg noclosing
+  error in definition for alias 'noclosingquotation': No closing quotation
+  [1]
+  $ hg help noclosing
+  error in definition for alias 'noclosingquotation': No closing quotation
+
+
 invalid options
 
   $ hg no--cwd