mirror of
https://github.com/sbt/sbt.git
synced 2026-10-06 10:03:56 +02:00
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
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user