Mercurial > hg-stable
comparison mercurial/extensions.py @ 47026:553451522113 stable
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
author | Matt Harbison <matt_harbison@yahoo.com> |
---|---|
date | Fri, 30 Apr 2021 17:36:09 -0400 |
parents | d4ba4d51f85f |
children | 7bafe40ab78a |
comparison
equal
deleted
inserted
replaced
47025:9cea55ca1175 | 47026:553451522113 |
---|---|
928 | 928 |
929 | 929 |
930 def moduleversion(module): | 930 def moduleversion(module): |
931 '''return version information from given module as a string''' | 931 '''return version information from given module as a string''' |
932 if util.safehasattr(module, b'getversion') and callable(module.getversion): | 932 if util.safehasattr(module, b'getversion') and callable(module.getversion): |
933 version = module.getversion() | 933 try: |
934 version = module.getversion() | |
935 except Exception: | |
936 version = b'unknown' | |
937 | |
934 elif util.safehasattr(module, b'__version__'): | 938 elif util.safehasattr(module, b'__version__'): |
935 version = module.__version__ | 939 version = module.__version__ |
936 else: | 940 else: |
937 version = b'' | 941 version = b'' |
938 if isinstance(version, (list, tuple)): | 942 if isinstance(version, (list, tuple)): |