From 0332250877be4266e6cf590b159e155acaba246f Mon Sep 17 00:00:00 2001 From: Lukas Juhrich Date: Sat, 25 Sep 2021 05:55:24 +0200 Subject: [PATCH] improve `BadZipFile` reporting --- src/pip/_internal/metadata/__init__.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/pip/_internal/metadata/__init__.py b/src/pip/_internal/metadata/__init__.py index f4f2a4f6cdb..58d7f890294 100644 --- a/src/pip/_internal/metadata/__init__.py +++ b/src/pip/_internal/metadata/__init__.py @@ -47,5 +47,12 @@ def get_wheel_distribution(wheel: Wheel, canonical_name: str) -> BaseDistributio :param canonical_name: Normalized project name of the given wheel. """ from .pkg_resources import Distribution - - return Distribution.from_wheel(wheel, canonical_name) + from zipfile import BadZipFile + + try: + return Distribution.from_wheel(wheel, canonical_name) + except BadZipFile as e: + raise RuntimeError( + "Unable to retrieve wheel {} with canonical name {}" + .format(wheel.location, canonical_name) + ) from e