# HG changeset patch # User Matt Harbison # Date 1583300754 18000 # Node ID 09f3e003fc2a694f672b01ca4cdf21127a6e8e76 # Parent 4152183aceddb48b15467dea90e160d52b6fed17 phabricator: avoid a stacktrace when command arguments are missing Previously, the TypeError wasn't properly converted to a SignatureError when improper arguments were supplied to the inner function, because the stack depth is 2 inside the vcrcommand decorator. The `__name__` and `__doc__` attributes need to be reassigned to the new wrapper so that the help summary is available. Differential Revision: https://phab.mercurial-scm.org/D8209 diff -r 4152183acedd -r 09f3e003fc2a hgext/phabricator.py --- a/hgext/phabricator.py Fri Jan 24 15:51:19 2020 -0800 +++ b/hgext/phabricator.py Wed Mar 04 00:45:54 2020 -0500 @@ -257,15 +257,17 @@ return fn(*args, **kwargs) return fn(*args, **kwargs) - inner.__name__ = fn.__name__ - inner.__doc__ = fn.__doc__ + cmd = util.checksignature(inner, depth=2) + cmd.__name__ = fn.__name__ + cmd.__doc__ = fn.__doc__ + return command( name, fullflags, spec, helpcategory=helpcategory, optionalrepo=optionalrepo, - )(inner) + )(cmd) return decorate diff -r 4152183acedd -r 09f3e003fc2a mercurial/util.py --- a/mercurial/util.py Fri Jan 24 15:51:19 2020 -0800 +++ b/mercurial/util.py Wed Mar 04 00:45:54 2020 -0500 @@ -1846,14 +1846,14 @@ return pycompat.ossep.join(([b'..'] * len(a)) + b) or b'.' -def checksignature(func): +def checksignature(func, depth=1): '''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: + if len(traceback.extract_tb(sys.exc_info()[2])) == depth: raise error.SignatureError raise diff -r 4152183acedd -r 09f3e003fc2a tests/test-phabricator.t --- a/tests/test-phabricator.t Fri Jan 24 15:51:19 2020 -0800 +++ b/tests/test-phabricator.t Wed Mar 04 00:45:54 2020 -0500 @@ -29,6 +29,21 @@ > --test-vcr "$VCR/phabread-conduit-error.json" D4480 | head abort: Conduit Error (ERR-INVALID-AUTH): API token "cli-notavalidtoken" has the wrong length. API tokens should be 32 characters long. +Missing arguments print the command help + + $ hg phabread + hg phabread: invalid arguments + hg phabread DREVSPEC [OPTIONS] + + print patches from Phabricator suitable for importing + + options: + + --stack read dependencies + + (use 'hg phabread -h' to show more help) + [255] + Basic phabread: $ hg phabread --test-vcr "$VCR/phabread-4480.json" D4480 | head # HG changeset patch