[PATCH STABLE] alias: handle shlex error in command aliases
Yuya Nishihara
yuya at tcha.org
Sat May 17 00:12:59 CDT 2014
On Fri, 16 May 2014 21:42:31 -0700, Pierre-Yves David wrote:
> On 05/16/2014 09:37 PM, Yuya Nishihara wrote:
> > # HG changeset patch
> > # User Yuya Nishihara <yuya at tcha.org>
> > # Date 1400299576 -32400
> > # Sat May 17 13:06:16 2014 +0900
> > # Branch stable
> > # Node ID 83696824c83f8a8a28ea02bf482c63d9d79a089d
> > # Parent 54d7657d7d1e6a62315eea53f4498657e766bb60
> > alias: handle shlex error in command aliases
>
> A wild bug fix appear! Thanks!
>
> > No command should fail with ValueError just because there is unparseable
> > alias definition.
>
> But no command command should pretend to succeed when there miserably
> failed:
>
> Could we raise an Abort Error instead?
>
> >
> > diff --git a/mercurial/dispatch.py b/mercurial/dispatch.py
> > --- a/mercurial/dispatch.py
> > +++ b/mercurial/dispatch.py
> > @@ -383,7 +383,16 @@ class cmdalias(object):
> > 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)
> >
> > diff --git a/tests/test-alias.t b/tests/test-alias.t
> > --- a/tests/test-alias.t
> > +++ b/tests/test-alias.t
> > @@ -10,6 +10,7 @@
> > > ambiguous = s
> > > recursive = recursive
> > > nodefinition =
> > + > noclosingquotation = '
> > > no--cwd = status --cwd elsewhere
> > > no-R = status -R elsewhere
> > > no--repo = status --repo elsewhere
> > @@ -86,6 +87,14 @@ no definition
> > no definition for alias 'nodefinition'
> >
> >
> > +no closing quotation
> > +
> > + $ hg noclosing
> > + error in definition for alias 'noclosingquotation': No closing quotation
>
> Raising AbortError will turn this in:
>
> error in definition for alias 'noclosingquotation': No closing quotation
> [255] ← Something terrible happen return code.
It's the same for the other badalias handlers in cmdalias.__init__.
I guess they try to exit with 1, but can't because of missing return:
--- a/mercurial/dispatch.py
+++ b/mercurial/dispatch.py
@@ -454,7 +454,7 @@ class cmdalias(object):
return self.fn(ui, *args, **opts)
else:
try:
- util.checksignature(self.fn)(ui, *args, **opts)
+ return util.checksignature(self.fn)(ui, *args, **opts)
except error.SignatureError:
args = ' '.join([self.cmdname] + self.args)
ui.debug("alias '%s' expands to '%s'\n" % (self.name, args))
I'll resend new version.
Regards,
More information about the Mercurial-devel
mailing list