Bug 2286 - bookmark command alias gives TypeError for invalid arguments
Summary: bookmark command alias gives TypeError for invalid arguments
Status: RESOLVED FIXED
Alias: None
Product: Mercurial
Classification: Unclassified
Component: Mercurial (show other bugs)
Version: unspecified
Hardware: All All
: normal bug
Assignee: Bugzilla
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-07-14 13:39 UTC by brodie
Modified: 2012-05-13 04:48 UTC (History)
5 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 brodie 2010-07-14 13:39 UTC
Normally "hg bookmarks" will correctly say "invalid arguments" when given multiple positional arguments (it 
only accepts a single bookmark name). However, when the command is called from an alias under this 
circumstance, hg raises a TypeError.

$ hg init foo
$ cd foo
$ hg bookmark foo
$ hg bookmark bar
$ hg --config alias.bm=bookmark bm -d foo bar
** unknown exception encountered, details follow
** report bug details to http://mercurial.selenic.com/bts/
** or mercurial@selenic.com
** Python 2.7 (r27:82500, Jul 11 2010, 23:01:58) [GCC 4.2.1 (Apple Inc. build 5664)]
** Mercurial Distributed SCM (version 1.6)
** Extensions loaded: bookmarks
Traceback (most recent call last):
  File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/bin/hg", line 27, in <module>
    mercurial.dispatch.run()
  File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-
packages/mercurial/dispatch.py", line 16, in run
    sys.exit(dispatch(sys.argv[1:]))
  File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-
packages/mercurial/dispatch.py", line 34, in dispatch
    return _runcatch(u, args)
  File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-
packages/mercurial/dispatch.py", line 54, in _runcatch
    return _dispatch(ui, args)
  File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-
packages/mercurial/dispatch.py", line 483, in _dispatch
    cmdpats, cmdoptions)
  File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-
packages/mercurial/dispatch.py", line 351, in runcommand
    ret = _runcommand(ui, options, cmd, d)
  File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-
packages/mercurial/dispatch.py", line 534, in _runcommand
    return checkargs()
  File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-
packages/mercurial/dispatch.py", line 488, in checkargs
    return cmdfunc()
  File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-
packages/mercurial/dispatch.py", line 481, in <lambda>
    d = lambda: util.checksignature(func)(ui, *args, **cmdoptions)
  File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-
packages/mercurial/util.py", line 420, in check
    return func(*args, **kwargs)
  File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-
packages/mercurial/dispatch.py", line 251, in __call__
    return self.fn(ui, *args, **opts)
TypeError: bookmark() got multiple values for keyword argument 'rev'
Comment 1 Renato Cunha 2010-07-22 10:16 UTC
Do you have some thoughts on what would be a satisfactory fix?

Resolving the alias early before calling checkargs(), perhaps?
Comment 2 Renato Cunha 2010-07-22 10:26 UTC
Ok, forget what I said. Everything is being resolved.

The TypeError is being reraised by util.py's checksignature():

def checksignature(func):
    '''wrap a function with code to check for calling errors'''
    def check(*args, **kwargs):
        try:
            return func(*args, **kwargs)
        except TypeError:
            if len(traceback.extract_tb(sys.exc_info()[2])) == 1:
                raise error.SignatureError
            raise # <- And here the TypeError is being reraised...

    return check
Comment 3 Renato Cunha 2010-07-22 10:32 UTC
I don't get (yet) what does that traceback.extract_tb(...) == 1 line wants
to do. But here is the diff on the tracebacks when that check is commented:

(old is from plain bookmark, new is from the alias)

bmark.old bmark.new                      
--- bmark.old   2010-07-22 13:30:49.458007189 -0300
+++ bmark.new   2010-07-22 13:30:10.571344044 -0300
@@ -25,4 +25,6 @@
     d = lambda: util.checksignature(func)(ui, *args, **cmdoptions)
   File "/mnt/0xdeadbeef/trovao/mercurial/hg/mercurial/util.py", line 426,
in check
     return func(*args, **kwargs)
+  File "/mnt/0xdeadbeef/trovao/mercurial/hg/mercurial/dispatch.py", line
265, in __call__
+    return self.fn(ui, *args, **opts)
 TypeError: bookmark() got multiple values for keyword argument 'rev'
Comment 4 Renato Cunha 2010-07-22 11:40 UTC
I had a quick chat with __ap__ in IRC.

One of the ideas that he pointed out could be that SignatureError could
always be raised like in 'except TypeError as e:  raise
SignatureError(*e.args)'.

To check for a TypeError inside the function being called, "we could check
that the traceback's most inner frame is in the function being called this
could be checked by comparing the code object of the frame with the code
object of the function".

Of course, this bug would still persist, but the check, perhaps, would be
prettier. Anyway, I don't know what else to do with it.
Comment 5 brodie 2010-07-26 08:08 UTC
Fixed in e4357c214bf1.
Comment 6 HG Bot 2010-07-30 22:00 UTC
Fixed by http://hg.intevation.org/mercurial/crew/rev/e4357c214bf1
Brodie Rao <brodie@bitheap.org>
alias: ensure checksignature() is applied directly to the command (issue2286)
Comment 7 Bugzilla 2012-05-12 09:10 UTC

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

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