mirror of https://github.com/sbt/sbt.git
Catch exception when reading file
This commit is contained in:
parent
127e73abe9
commit
88cd8909a3
|
|
@ -849,9 +849,17 @@ object Cache {
|
|||
logger = logger,
|
||||
pool = pool,
|
||||
ttl = ttl
|
||||
).leftMap(_.describe).map { f =>
|
||||
// FIXME Catch error here?
|
||||
new String(NioFiles.readAllBytes(f.toPath), "UTF-8")
|
||||
).leftMap(_.describe).flatMap { f =>
|
||||
val res = if (!f.isDirectory && f.exists()) {
|
||||
Try(new String(NioFiles.readAllBytes(f.toPath), "UTF-8")) match {
|
||||
case scala.util.Success(content) =>
|
||||
Right(content)
|
||||
case scala.util.Failure(e) =>
|
||||
Left(s"Could not read (file:${f.getCanonicalPath}): ${e.getMessage}")
|
||||
}
|
||||
} else Left(s"Could not read (file:${f.getCanonicalPath}) (isFile:${!f.isDirectory}) (exists:${f.exists()})")
|
||||
|
||||
EitherT.fromEither(Task.now[Either[String, String]](res))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue