@@ -194,7 +194,17 @@ def __init__(
194194 self .origin : Optional [DirectUrl ] = None
195195 origin_direct_url_path = Path (self .link .file_path ).parent / ORIGIN_JSON_NAME
196196 if origin_direct_url_path .exists ():
197- self .origin = DirectUrl .from_json (origin_direct_url_path .read_text ())
197+ try :
198+ self .origin = DirectUrl .from_json (
199+ origin_direct_url_path .read_text (encoding = "utf-8" )
200+ )
201+ except Exception as e :
202+ logger .warning (
203+ "Ignoring invalid cache entry origin file %s for %s (%s)" ,
204+ origin_direct_url_path ,
205+ link .filename ,
206+ e ,
207+ )
198208
199209
200210class WheelCache (Cache ):
@@ -257,16 +267,26 @@ def get_cache_entry(
257267 @staticmethod
258268 def record_download_origin (cache_dir : str , download_info : DirectUrl ) -> None :
259269 origin_path = Path (cache_dir ) / ORIGIN_JSON_NAME
260- if origin_path .is_file ():
261- origin = DirectUrl .from_json (origin_path .read_text ())
262- # TODO: use DirectUrl.equivalent when https://github.com/pypa/pip/pull/10564
263- # is merged.
264- if origin .url != download_info .url :
270+ if origin_path .exists ():
271+ try :
272+ origin = DirectUrl .from_json (origin_path .read_text (encoding = "utf-8" ))
273+ except Exception as e :
265274 logger .warning (
266- "Origin URL %s in cache entry %s does not match download URL %s. "
267- "This is likely a pip bug or a cache corruption issue." ,
268- origin .url ,
269- cache_dir ,
270- download_info .url ,
275+ "Could not read origin file %s in cache entry (%s). "
276+ "Will attempt to overwrite it." ,
277+ origin_path ,
278+ e ,
271279 )
280+ else :
281+ # TODO: use DirectUrl.equivalent when
282+ # https://github.com/pypa/pip/pull/10564 is merged.
283+ if origin .url != download_info .url :
284+ logger .warning (
285+ "Origin URL %s in cache entry %s does not match download URL "
286+ "%s. This is likely a pip bug or a cache corruption issue. "
287+ "Will overwrite it with the new value." ,
288+ origin .url ,
289+ cache_dir ,
290+ download_info .url ,
291+ )
272292 origin_path .write_text (download_info .to_json (), encoding = "utf-8" )
0 commit comments