From b545c279eb213e2d57fb6b2b856a71d20e4fa590 Mon Sep 17 00:00:00 2001 From: James Gerity Date: Mon, 28 Oct 2024 21:23:02 -0400 Subject: [PATCH] plugins.handlers: warn when version determination fails --- sopel/plugins/handlers.py | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/sopel/plugins/handlers.py b/sopel/plugins/handlers.py index 3ef85fc6b..eee1c056d 100644 --- a/sopel/plugins/handlers.py +++ b/sopel/plugins/handlers.py @@ -48,6 +48,7 @@ import importlib.util import inspect import itertools +import logging import os import sys from typing import Optional, TYPE_CHECKING, TypedDict @@ -61,6 +62,9 @@ from types import ModuleType +LOGGER = logging.getLogger(__name__) + + class PluginMetaDescription(TypedDict): """Meta description of a plugin, as a dictionary. @@ -623,11 +627,17 @@ def get_version(self) -> Optional[str]: and hasattr(self.entry_point, "dist") and hasattr(self.entry_point.dist, "name") ): + dist_name = self.entry_point.dist.name try: - version = importlib.metadata.version(self.entry_point.dist.name) + version = importlib.metadata.version(dist_name) + except (ValueError, importlib.metadata.PackageNotFoundError): + LOGGER.warning("Cannot determine version of %r", dist_name) except Exception: - # fine, just give up - pass + LOGGER.warning( + "Unexpected error occurred while checking the version of %r", + dist_name, + exc_info=True, + ) return version