Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: don't fail if cache is corrupted #7728

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion src/poetry/utils/cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import dataclasses
import hashlib
import json
import logging
import shutil
import time

Expand All @@ -23,6 +24,7 @@

from poetry.utils.env import Env

logger = logging.getLogger(__name__)

# Used by Cachy for items that do not expire.
MAX_DATE = 9999999999
Expand Down Expand Up @@ -182,7 +184,17 @@ def _get_payload(self, key: str) -> T | None:
return None

with open(path, "rb") as f:
payload = self._deserialize(f.read())
try:
payload = self._deserialize(f.read())
except json.JSONDecodeError as exc:
logger.warning(
"Invalid cache entry (%s) found in %s: %s",
key,
path,
str(exc),
)
self.forget(key)
return None

if payload.expired:
self.forget(key)
Expand Down