Skip to content

Commit

Permalink
More info about exceptions without messages (#48) (#49)
Browse files Browse the repository at this point in the history
  • Loading branch information
poslegm authored Sep 16, 2019
1 parent 3023c96 commit b1110b6
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions plugin/src/main/scala/org/scalafmt/sbt/ScalafmtSbtReporter.scala
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,21 @@ import org.scalafmt.interfaces.ScalafmtReporter
import sbt.internal.util.MessageOnlyException
import sbt.util.Logger

import scala.util.control.NoStackTrace

class ScalafmtSbtReporter(log: Logger, writer: PrintWriter)
extends ScalafmtReporter {
override def error(file: Path, message: String): Unit = {
throw new MessageOnlyException(s"$message: $file")
}

override def error(file: Path, e: Throwable): Unit =
error(file, e.getMessage)
override def error(file: Path, e: Throwable): Unit = {
if (e.getMessage != null) {
error(file, e.getMessage)
} else {
throw new FailedToFormat(file.toString, e)
}
}

override def excluded(file: Path): Unit =
log.debug(s"file excluded: $file")
Expand All @@ -23,4 +30,8 @@ class ScalafmtSbtReporter(log: Logger, writer: PrintWriter)
log.debug(s"parsed config (v$scalafmtVersion): $config")

override def downloadWriter(): PrintWriter = writer

private class FailedToFormat(filename: String, cause: Throwable)
extends Exception(filename, cause)
with NoStackTrace
}

0 comments on commit b1110b6

Please sign in to comment.