comparison mercurial/util.py @ 44436: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
comparison
equal deleted inserted replaced
44435:4152183acedd 44436:09f3e003fc2a
1844 b.pop() 1844 b.pop()
1845 b.reverse() 1845 b.reverse()
1846 return pycompat.ossep.join(([b'..'] * len(a)) + b) or b'.' 1846 return pycompat.ossep.join(([b'..'] * len(a)) + b) or b'.'
1847 1847
1848 1848
1849 def checksignature(func): 1849 def checksignature(func, depth=1):
1850 '''wrap a function with code to check for calling errors''' 1850 '''wrap a function with code to check for calling errors'''
1851 1851
1852 def check(*args, **kwargs): 1852 def check(*args, **kwargs):
1853 try: 1853 try:
1854 return func(*args, **kwargs) 1854 return func(*args, **kwargs)
1855 except TypeError: 1855 except TypeError:
1856 if len(traceback.extract_tb(sys.exc_info()[2])) == 1: 1856 if len(traceback.extract_tb(sys.exc_info()[2])) == depth:
1857 raise error.SignatureError 1857 raise error.SignatureError
1858 raise 1858 raise
1859 1859
1860 return check 1860 return check
1861 1861