Merge pull request #8332 from mrdziuban/incomplete-parse-exception

This commit is contained in:
eugene yokota 2025-10-08 10:08:30 -04:00 committed by GitHub
commit 7b26748599
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 27 additions and 2 deletions

View File

@ -195,9 +195,9 @@ class DiskActionCacheStore(base: Path, converter: FileConverter) extends Abstrac
override def get(request: GetActionResultRequest): Either[Throwable, ActionResult] =
val acFile = acBase.toFile / request.actionDigest.toString.replace("/", "-")
if acFile.exists then
val str = IO.read(acFile)
val json = Parser.parseUnsafe(str)
try
val str = IO.read(acFile)
val json = Parser.parseUnsafe(str)
val value = Converter.fromJsonUnsafe[ActionResult](json)
if request.inlineOutputFiles.isEmpty then Right(value)
else

View File

@ -80,6 +80,31 @@ object ActionCacheTest extends BasicTestSuite:
// check that the action has been invoked only once
assert(called == 1)
test("Disk cache can recover gracefully from invalid JSON"):
withDiskCache(testActionCacheInvalidJson)
def testActionCacheInvalidJson(cache: DiskActionCacheStore): Unit =
import sjsonnew.BasicJsonProtocol.*
var called = 0
val action: ((Int, Int)) => InternalActionResult[Int] = { (a, b) =>
called += 1
InternalActionResult(a + b, Nil)
}
IO.withTemporaryDirectory: tempDir =>
val config = getCacheConfig(cache, tempDir)
val v1 = ActionCache.cache((1, 1), Digest.zero, Digest.zero, tags, config)(action)
assert(v1 == 2)
val acFiles = cache.acBase.toFile.listFiles
assert(acFiles.length == 1)
IO.write(acFiles.head, "{")
val v2 = ActionCache.cache((1, 1), Digest.zero, Digest.zero, tags, config)(action)
assert(v2 == 2)
// check that the action has been invoked twice
assert(called == 2)
def withInMemoryCache(f: InMemoryActionCacheStore => Unit): Unit =
val cache = InMemoryActionCacheStore()
f(cache)