Bug 3332 - Too few arguments to an alias causes a stacktrace
Summary: Too few arguments to an alias causes a stacktrace
Status: RESOLVED FIXED
Alias: None
Product: Mercurial
Classification: Unclassified
Component: Mercurial (show other bugs)
Version: unspecified
Hardware: All All
: normal bug
Assignee: Matt Mackall
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2012-03-22 08:03 UTC by Mike Williams
Modified: 2018-03-27 00:00 UTC (History)
4 users (show)

See Also:
Python Version: ---


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Mike Williams 2012-03-22 08:03 UTC
Missing an argument to an alias using positional arguments throws a stacktrace.

F:\temp\branching> hg --config alias.bob="log --style $1 --rev $2" bob compact
** unknown exception encountered, please report by visiting
**  http://mercurial.selenic.com/wiki/BugTracker
** Python 2.6.6 (r266:84297, Aug 24 2010, 18:13:38) [MSC v.1500 64 bit (AMD64)]
** Mercurial Distributed SCM (version 2.1.1)
** Extensions loaded:
Traceback (most recent call last):
  File "hg", line 42, in <module>
  File "mercurial\dispatch.pyo", line 27, in run
  File "mercurial\dispatch.pyo", line 64, in dispatch
  File "mercurial\dispatch.pyo", line 87, in _runcatch
  File "mercurial\dispatch.pyo", line 578, in _dispatch
  File "mercurial\dispatch.pyo", line 386, in _parse
  File "mercurial\dispatch.pyo", line 229, in aliasargs
  File "re.pyo", line 151, in sub
  File "mercurial\dispatch.pyo", line 228, in replacer
IndexError: list index out of range
Comment 1 HG Bot 2012-03-22 17:00 UTC
Fixed by http://selenic.com/repo/hg/rev/1c2aaf05f7d7
Matt Mackall <mpm@selenic.com>
aliases: use empty string for missing position parameters (issue3331)

(please test the fix)
Comment 2 Mike Williams 2012-03-23 04:45 UTC
Fix tested:

H:\hg\hg-stable>hg-Python26\python hg.py --config alias.bob="log --style $1
--rev $2" bob compact
hg: parse error: empty query

Confirm no more exception traceback reported.

However the error reported is not helpful.  There is no indication whether
it is too few args to the alias or a deeper problem in mercurial processing
the command.  In the case above for --rev I expected to see what normally
happens when the rev is omitted:

H:\hg\hg-stable>hg-Python26\python hg.py log --rev
hg log: option --rev requires argument
hg log [OPTION]... [FILE]
...

What happens is effectively hg log --rev "" which is not obvious, and the
replacement with an empty string may have different results for different
command arguments (e.g. a commit alias with a positional arg for the commit
message that is no supplied.)  I'd be happy with just reporting fewer
arguments than required by the alias.
Comment 3 Mike Williams 2012-03-23 04:58 UTC
The following would be more helpful in my view as it is more obvious where
the source of the problem is:

H:\hg\hg-stable>hg-python26\python hg.py diff
diff -r 900eee0778d1 mercurial/dispatch.py
--- a/mercurial/dispatch.py     Thu Mar 22 17:07:39 2012 -0500
+++ b/mercurial/dispatch.py     Fri Mar 23 10:52:10 2012 +0000
@@ -227,7 +227,7 @@
             nums.append(num)
             if num < len(givenargs):
                 return givenargs[num]
-            return ''
+            raise util.Abort(_('too few arguments for command alias'))
         cmd = re.sub(r'\$(\d+|\$)', replacer, cmd)
         givenargs = [x for i, x in enumerate(givenargs)
                      if i not in nums]

H:\hg\hg-stable>hg-python26\python hg.py --config alias.bob="log --style $1
--rev $2" bob compact
abort: too few arguments for command alias
Comment 4 HG Bot 2012-03-27 16:00 UTC
Fixed by http://selenic.com/repo/hg/rev/795d591b6ef5
Matt Mackall <mpm@selenic.com>
alias: abort on missing positional args (issue3331)

(please test the fix)
Comment 5 Mike Williams 2012-03-28 03:17 UTC
Yay, happy dance!  Works for me - many thanks.
Comment 6 Bugzilla 2012-05-12 09:29 UTC

--- Bug imported by bugzilla@serpentine.com 2012-05-12 09:29 EDT  ---

This bug was previously known as _bug_ 3331 at http://mercurial.selenic.com/bts/issue3331

Bug Status was UNCONFIRMED but everconfirmed was true
   Setting status to CONFIRMED

Comment 7 HG Bot 2018-03-19 21:50 UTC
Fixed by https://mercurial-scm.org/repo/hg/rev/a046d6890761
Martin von Zweigbergk <martinvonz@google.com>
rebase: avoid defining two lists with the same contents

In abort(), there's "dstates" and "rebased" that are identical, which
they seem to have been since 0806823370d8 (rebase: properly calculate
descendant set when aborting (issue3332), 2012-03-22). Let's
de-duplicate. I don't know what "dstates" means, but "rebased" makes
sense (it's the list of rebased revisions), so let's pick that.

Differential Revision: https://phab.mercurial-scm.org/D2878

(please test the fix)
Comment 8 Bugzilla 2018-03-27 00:00 UTC
Bug was set to TESTING for 7 days, resolving