From 08fe019dc0fc1c0b173b59abc0658fb210ed1cd0 Mon Sep 17 00:00:00 2001 From: john0030710 Date: Sat, 10 Jan 2026 00:23:05 +0100 Subject: [PATCH] Use proper exception handling with Exception.nonFatalCatch.opt - Replace try-catch with Exception.nonFatalCatch.opt for cleaner code - Follows Scala best practices for non-fatal exception handling - More functional and idiomatic approach - Avoids catching fatal exceptions like VirtualMachineError --- util-cache/src/main/scala/sbt/util/ActionCache.scala | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/util-cache/src/main/scala/sbt/util/ActionCache.scala b/util-cache/src/main/scala/sbt/util/ActionCache.scala index 5d9895940..88bfa3803 100644 --- a/util-cache/src/main/scala/sbt/util/ActionCache.scala +++ b/util-cache/src/main/scala/sbt/util/ActionCache.scala @@ -19,6 +19,7 @@ import sbt.nio.file.syntax.* import sbt.util.CacheImplicits import scala.reflect.ClassTag import scala.annotation.{ meta, StaticAnnotation } +import scala.util.control.Exception import sjsonnew.{ HashWriter, JsonFormat } import sjsonnew.support.murmurhash.Hasher import sjsonnew.support.scalajson.unsafe.{ CompactPrinter, Converter, Parser } @@ -111,10 +112,9 @@ object ActionCache: if java.nio.file.Files.isSymbolicLink(resolvedValuePath) && java.nio.file.Files .exists(resolvedValuePath) then - try - val str = IO.read(resolvedValuePath.toFile(), StandardCharsets.UTF_8) - Some(valueFromStr(str, Some("symlink"))) - catch case _: Exception => None + Exception.nonFatalCatch + .opt(IO.read(resolvedValuePath.toFile(), StandardCharsets.UTF_8)) + .map(valueFromStr(_, Some("symlink"))) else None readFromSymlink() match