Skip to content

Commit

Permalink
Exception.getMessage can be null
Browse files Browse the repository at this point in the history
  • Loading branch information
alexarchambault committed May 6, 2016
1 parent 3834a95 commit 00484df
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 25 deletions.
16 changes: 2 additions & 14 deletions cache/src/main/scala/coursier/Cache.scala
Expand Up @@ -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 = {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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)

Expand Down
2 changes: 1 addition & 1 deletion cache/src/main/scala/coursier/CacheParse.scala
Expand Up @@ -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
}
}

Expand Down
4 changes: 2 additions & 2 deletions cache/src/main/scala/coursier/Platform.scala
Expand Up @@ -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("")(" (" + _ + ")")}"
}
}

Expand Down
7 changes: 5 additions & 2 deletions cli/src/main/scala-2.11/coursier/cli/Bootstrap.scala
Expand Up @@ -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)
}

Expand All @@ -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)
}

Expand Down
Expand Up @@ -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 {
Expand Down
9 changes: 5 additions & 4 deletions fetch-js/src/main/scala/coursier/Platform.scala
Expand Up @@ -80,7 +80,7 @@ object Platform {
get(artifact.url)
.map(\/-(_))
.recover { case e: Exception =>
-\/(e.getMessage)
-\/(e.toString + Option(e.getMessage).fold("")(" (" + _ + ")"))
}
}
)
Expand All @@ -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)
}
}
)
}
Expand Down
2 changes: 1 addition & 1 deletion plugin/src/main/scala-2.10/coursier/FromSbt.scala
Expand Up @@ -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"
)

Expand Down

0 comments on commit 00484df

Please sign in to comment.