Mercurial > public > mercurial-scm > hg-stable
diff mercurial/util.py @ 44456:09f3e003fc2a
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
author | Matt Harbison <matt_harbison@yahoo.com> |
---|---|
date | Wed, 04 Mar 2020 00:45:54 -0500 |
parents | a61287a95dc3 |
children | 9d2b2df2c2ba |
line wrap: on
line diff
--- 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