# HG changeset patch # User Matt Harbison # Date 1619818569 14400 # Node ID 553451522113ee0304835b8005e74695f36d1333 # Parent 9cea55ca117535a092c9e6fb5e0edf1a5a6b6fd4 extensions: ignore exceptions from an extension's `getversion()` method 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. Use 'unknown' to signal that it tried to report a version and failed, unlike the default case of printing nothing. Differential Revision: https://phab.mercurial-scm.org/D10540 diff -r 9cea55ca1175 -r 553451522113 mercurial/extensions.py --- a/mercurial/extensions.py Wed Apr 28 17:05:32 2021 -0400 +++ b/mercurial/extensions.py Fri Apr 30 17:36:09 2021 -0400 @@ -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'unknown' + elif util.safehasattr(module, b'__version__'): version = module.__version__ else: