Skip to content

Commit 07a0d2f

Browse files
catch an exception when parsing metadata which only occurs in CI
1 parent 1b94a91 commit 07a0d2f

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed

src/pip/_internal/operations/prepare.py

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
# The following comment should be removed at some point in the future.
55
# mypy: strict-optional=False
66

7+
import email.errors
78
import json
89
import mimetypes
910
import os
@@ -455,11 +456,19 @@ def _cache_metadata(
455456
) -> None:
456457
if self._metadata_cache is None:
457458
return
458-
with self._metadata_cache.cache_path(link).open("w") as f:
459-
cacheable_dist = CacheableDist.from_dist(link, metadata_dist)
460-
args = cacheable_dist.to_json()
461-
logger.debug("caching metadata for link %s at %s", link.url, f.name)
462-
json.dump(args, f)
459+
try:
460+
with self._metadata_cache.cache_path(link).open("w") as f:
461+
cacheable_dist = CacheableDist.from_dist(link, metadata_dist)
462+
args = cacheable_dist.to_json()
463+
logger.debug("caching metadata for link %s at %s", link.url, f.name)
464+
json.dump(args, f)
465+
except email.errors.HeaderParseError as e:
466+
logger.debug(
467+
"could not cache metadata for dist %s from %s: %s",
468+
metadata_dist,
469+
link,
470+
e,
471+
)
463472

464473
def _fetch_metadata_using_link_data_attr(
465474
self,

0 commit comments

Comments
 (0)