Patchwork D10540: extensions: ignore exceptions from an extension's `getversion()` method

login
register
mail settings
Submitter phabricator
Date May 1, 2021, 12:47 a.m.
Message ID <differential-rev-PHID-DREV-xtxnul2jsw6zte5rnnsq-req@mercurial-scm.org>
Download mbox | patch
Permalink /patch/48859/
State Superseded
Headers show

Comments

phabricator - May 1, 2021, 12:47 a.m.
mharbison72 created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.

REVISION SUMMARY
  This method is usually called when there's a stacktrace being generated, or with
  `hg version -v`.  Raising another exception risks mangling the bug report info.
  
  I hit this issue when trying to add the method to the keyring extension to
  report the version of the extension and the underlying module, and ran into
  demandimport issues prior to py3.8.  It seems like a wise thing to do anyway,
  though unfortunately there's no convenient `ui` object around to issue a
  warning.

REPOSITORY
  rHG Mercurial

BRANCH
  stable

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

AFFECTED FILES
  mercurial/extensions.py

CHANGE DETAILS




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

Patch

diff --git a/mercurial/extensions.py b/mercurial/extensions.py
--- a/mercurial/extensions.py
+++ b/mercurial/extensions.py
@@ -930,7 +930,11 @@ 
 def moduleversion(module):
     '''return version information from given module as a string'''
     if util.safehasattr(module, b'getversion') and callable(module.getversion):
-        version = module.getversion()
+        try:
+            version = module.getversion()
+        except Exception:
+            version = b''
+
     elif util.safehasattr(module, b'__version__'):
         version = module.__version__
     else: