D10540: extensions: ignore exceptions from an extension's `getversion()` method
mharbison72 (Matt Harbison)
phabricator at mercurial-scm.org
Sat May 1 00:47:42 UTC 2021
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
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:
To: mharbison72, #hg-reviewers
Cc: mercurial-patches, mercurial-devel
More information about the Mercurial-devel
mailing list