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'
Do you have some thoughts on what would be a satisfactory fix? Resolving the alias early before calling checkargs(), perhaps?
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
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'
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.
Fixed in e4357c214bf1.
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)
--- 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