Subject: [PATCH 3/4] substitutes: Ignore corrupt cached narinfos.

From: Ludovic Courtès <[email-masked]>
Date: Wed, 9 Apr 2025 16:23:39 +0200

* guix/substitutes.scm (cached-narinfo): Wrap ‘read’ call in
‘false-if-exception’.  Add catch-all ‘match’ clause.

Change-Id: I2d776f64b6521f778b4ab3f956b35cdef2ddb383
---
 guix/substitutes.scm | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/guix/substitutes.scm b/guix/substitutes.scm
index 86b9f5472a..45c165e03e 100644
--- a/guix/substitutes.scm
+++ b/guix/substitutes.scm
@@ -300,7 +300,7 @@ (define (cached-narinfo cache-url path)
     (lambda ()
       (call-with-input-file cache-file
         (lambda (p)
-          (match (read p)
+          (match (false-if-exception (read p))
             (('narinfo ('version 2)
                        ('cache-uri cache-uri)
                        ('date date) ('ttl ttl) ('value #f))
@@ -315,7 +315,8 @@ (define (cached-narinfo cache-url path)
              (if (obsolete? date now ttl)
                  (values #f #f)
                  (values #t (string->narinfo value cache-uri))))
-            (('narinfo ('version v) _ ...)
+            (_
+             ;; Corrupt or incompatible cached entry.
              (values #f #f))))))
     (lambda _
       (values #f #f))))
-- 
2.49.0