Skip to content

Commit f072af8

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

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

src/pip/_internal/operations/prepare.py

Lines changed: 12 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,17 @@ 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.warn(
467+
f"could not parse metadata for dist {metadata_dist} from {link}"
468+
)
469+
logger.debug(e)
463470

464471
def _fetch_metadata_using_link_data_attr(
465472
self,

0 commit comments

Comments
 (0)