mirror of https://github.com/sbt/sbt.git
Merge pull request #305 from rtfpessoa/fix-exception-when-reading-files
Catch exception when reading file
This commit is contained in:
commit
350b4afaeb
|
|
@ -849,9 +849,17 @@ object Cache {
|
||||||
logger = logger,
|
logger = logger,
|
||||||
pool = pool,
|
pool = pool,
|
||||||
ttl = ttl
|
ttl = ttl
|
||||||
).leftMap(_.describe).map { f =>
|
).leftMap(_.describe).flatMap { f =>
|
||||||
// FIXME Catch error here?
|
val res = if (!f.isDirectory && f.exists()) {
|
||||||
new String(NioFiles.readAllBytes(f.toPath), "UTF-8")
|
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