D8209: phabricator: avoid a stacktrace when command arguments are missing

mharbison72 (Matt Harbison) phabricator at mercurial-scm.org
Wed Mar 4 21:17:32 UTC 2020


Closed by commit rHG09f3e003fc2a: phabricator: avoid a stacktrace when command arguments are missing (authored by mharbison72).
This revision was automatically updated to reflect the committed changes.
This revision was not accepted when it landed; it landed in state "Needs Review".

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST UPDATE
  https://phab.mercurial-scm.org/D8209?vs=20439&id=20488

CHANGES SINCE LAST ACTION
  https://phab.mercurial-scm.org/D8209/new/

REVISION DETAIL
  https://phab.mercurial-scm.org/D8209

AFFECTED FILES
  hgext/phabricator.py
  mercurial/util.py
  tests/test-phabricator.t

CHANGE DETAILS

diff --git a/tests/test-phabricator.t b/tests/test-phabricator.t
--- a/tests/test-phabricator.t
+++ b/tests/test-phabricator.t
@@ -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
diff --git a/mercurial/util.py b/mercurial/util.py
--- a/mercurial/util.py
+++ b/mercurial/util.py
@@ -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 --git a/hgext/phabricator.py b/hgext/phabricator.py
--- a/hgext/phabricator.py
+++ b/hgext/phabricator.py
@@ -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
 



To: mharbison72, #hg-reviewers
Cc: Kwan, mercurial-devel


More information about the Mercurial-devel mailing list