From 7d76f8f33edc2c351c0a2a972b30d75db5646e91 Mon Sep 17 00:00:00 2001 From: Eugene Yokota Date: Thu, 25 Dec 2025 04:38:43 -0500 Subject: [PATCH] [2.x] fix: Workaround for NoSuchFileException **Problem** In some scripted tests, we've seen NoSuchFileException. **Solution** Catch the exceptions related to caching. --- .../scala/sbt/util/ActionCacheStore.scala | 41 +++++++++++-------- 1 file changed, 25 insertions(+), 16 deletions(-) diff --git a/util-cache/src/main/scala/sbt/util/ActionCacheStore.scala b/util-cache/src/main/scala/sbt/util/ActionCacheStore.scala index 8d23dbeae..7a9838175 100644 --- a/util-cache/src/main/scala/sbt/util/ActionCacheStore.scala +++ b/util-cache/src/main/scala/sbt/util/ActionCacheStore.scala @@ -254,22 +254,28 @@ class DiskActionCacheStore(base: Path, converter: FileConverter) extends Abstrac private def getBlobs(refs: Seq[HashedVirtualFileRef]): Seq[VirtualFile] = refs.flatMap: r => - val casFile = toCasFile(Digest(r)) - if casFile.toFile().exists then - r match - case p: PathBasedFile => Some(p) - case _ => - val content = IO.read(casFile.toFile()) - Some(StringVirtualFile1(r.id, content)) - else None + try + val casFile = toCasFile(Digest(r)) + if casFile.toFile().exists then + r match + case p: PathBasedFile => Some(p) + case _ => + val content = IO.read(casFile.toFile()) + Some(StringVirtualFile1(r.id, content)) + else None + // Digest(r) can throw NoSuchFileException + catch case _: NoSuchFileException => None override def syncBlobs(refs: Seq[HashedVirtualFileRef], outputDirectory: Path): Seq[Path] = refs.flatMap: r => - val casFile = toCasFile(Digest(r)) - if casFile.toFile().exists then - // println(s"syncBlobs: $casFile exists for $r") - Some(syncFile(r, casFile, outputDirectory)) - else None + try + val casFile = toCasFile(Digest(r)) + if casFile.toFile().exists then + // println(s"syncBlobs: $casFile exists for $r") + Some(syncFile(r, casFile, outputDirectory)) + else None + // Digest(r) can throw NoSuchFileException + catch case _: NoSuchFileException => None def syncFile(ref: HashedVirtualFileRef, casFile: Path, outputDirectory: Path): Path = val d = Digest(ref) @@ -365,7 +371,10 @@ class DiskActionCacheStore(base: Path, converter: FileConverter) extends Abstrac override def findBlobs(refs: Seq[HashedVirtualFileRef]): Seq[HashedVirtualFileRef] = refs.flatMap: r => - val casFile = toCasFile(Digest(r)) - if casFile.toFile().exists then Some(r) - else None + try + val casFile = toCasFile(Digest(r)) + if casFile.toFile().exists then Some(r) + else None + // Digest(r) can throw NoSuchFileException + catch case _: NoSuchFileException => None end DiskActionCacheStore