Exception.getMessage can be null

This commit is contained in:
Alexandre Archambault 2016-05-06 13:53:53 +02:00
parent 3834a9519c
commit 00484df435
No known key found for this signature in database
GPG Key ID: 14640A6839C263A9
7 changed files with 17 additions and 25 deletions

View File

@ -204,7 +204,7 @@ object Cache {
-\/(FileError.ConcurrentDownload(url))
}
catch { case e: Exception =>
-\/(FileError.DownloadError(s"Caught $e (${e.getMessage})"))
-\/(FileError.DownloadError(s"Caught $e${Option(e.getMessage).fold("")(" (" + _ + ")")}"))
}
private def temporaryFile(file: File): File = {
@ -232,7 +232,7 @@ object Cache {
def printError(e: Exception): Unit =
scala.Console.err.println(
s"Cannot instantiate $clsName: $e${Option(e.getMessage).map(" ("+_+")")}"
s"Cannot instantiate $clsName: $e${Option(e.getMessage).fold("")(" ("+_+")")}"
)
val handlerOpt = clsOpt.flatMap {
@ -811,18 +811,6 @@ object Cache {
buffer.toByteArray
}
def readFully(is: => InputStream) =
Task {
\/.fromTryCatchNonFatal {
val is0 = is
val b =
try readFullySync(is0)
finally is0.close()
new String(b, "UTF-8")
} .leftMap(_.getMessage)
}
def withContent(is: InputStream, f: (Array[Byte], Int) => Unit): Unit = {
val data = Array.ofDim[Byte](16384)

View File

@ -31,7 +31,7 @@ object CacheParse {
repo.success
} catch {
case e: MalformedURLException =>
("Error parsing URL " + url + Option(e.getMessage).map(" (" + _ + ")").mkString).failure
("Error parsing URL " + url + Option(e.getMessage).fold("")(" (" + _ + ")")).failure
}
}

View File

@ -32,10 +32,10 @@ object Platform {
new String(b, "UTF-8")
} .leftMap{
case e: java.io.FileNotFoundException =>
case e: java.io.FileNotFoundException if e.getMessage != null =>
s"Not found: ${e.getMessage}"
case e =>
s"$e: ${e.getMessage}"
s"$e${Option(e.getMessage).fold("")(" (" + _ + ")")}"
}
}

View File

@ -193,7 +193,7 @@ case class Bootstrap(
try Files.write(output0.toPath, shellPreamble.getBytes("UTF-8") ++ buffer.toByteArray)
catch { case e: IOException =>
Console.err.println(s"Error while writing $output0: ${e.getMessage}")
Console.err.println(s"Error while writing $output0${Option(e.getMessage).fold("")(" (" + _ + ")")}")
sys.exit(1)
}
@ -218,7 +218,10 @@ case class Bootstrap(
case e: UnsupportedOperationException =>
// Ignored
case e: IOException =>
Console.err.println(s"Error while making $output0 executable: ${e.getMessage}")
Console.err.println(
s"Error while making $output0 executable" +
Option(e.getMessage).fold("")(" (" + _ + ")")
)
sys.exit(1)
}

View File

@ -14,7 +14,7 @@ package object compatibility {
def xmlParse(s: String): Either[String, Xml.Node] = {
def parse =
try Right(scala.xml.XML.loadString(s))
catch { case e: Exception => Left(e.getMessage) }
catch { case e: Exception => Left(e.toString + Option(e.getMessage).fold("")(" (" + _ + ")")) }
def fromNode(node: scala.xml.Node): Xml.Node =
new Xml.Node {

View File

@ -80,7 +80,7 @@ object Platform {
get(artifact.url)
.map(\/-(_))
.recover { case e: Exception =>
-\/(e.getMessage)
-\/(e.toString + Option(e.getMessage).fold("")(" (" + _ + ")"))
}
}
)
@ -104,9 +104,10 @@ object Platform {
.flatMap(_ => get(artifact.url))
.map { s => logger.fetched(artifact.url); \/-(s) }
.recover { case e: Exception =>
logger.other(artifact.url, e.getMessage)
-\/(e.getMessage)
}
val msg = e.toString + Option(e.getMessage).fold("")(" (" + _ + ")")
logger.other(artifact.url, msg)
-\/(msg)
}
}
)
}

View File

@ -155,7 +155,7 @@ object FromSbt {
log.warn(
"Error parsing Maven repository base " +
root +
Option(e.getMessage).map(" (" + _ + ")").mkString +
Option(e.getMessage).fold("")(" (" + _ + ")") +
", ignoring it"
)