From ecd49022a05d4c8bb1d9ba6d304d181016b27b08 Mon Sep 17 00:00:00 2001 From: tanishiking24 Date: Thu, 16 Jan 2020 23:23:14 +0900 Subject: [PATCH] Implement error method with an additinal erro message and cause Without this implementation, the reporter discard the error information of the `cause` like [CorruptedClassPath](https://github.com/scalameta/scalafmt/blob/dee798a99e16dcf32fea37cdc05d694b76647ada/scalafmt-dynamic/src/main/scala/org/scalafmt/dynamic/ScalafmtDynamic.scala#L96) https://github.com/scalameta/scalafmt/issues/1628 --- .../main/scala/org/scalafmt/sbt/ScalafmtSbtReporter.scala | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/plugin/src/main/scala/org/scalafmt/sbt/ScalafmtSbtReporter.scala b/plugin/src/main/scala/org/scalafmt/sbt/ScalafmtSbtReporter.scala index 81d69af..a1487bf 100644 --- a/plugin/src/main/scala/org/scalafmt/sbt/ScalafmtSbtReporter.scala +++ b/plugin/src/main/scala/org/scalafmt/sbt/ScalafmtSbtReporter.scala @@ -24,6 +24,14 @@ class ScalafmtSbtReporter(log: Logger, out: OutputStreamWriter) } } + override def error(file: Path, message: String, e: Throwable): Unit = { + if (e.getMessage != null) { + error(file, s"$message: ${e.getMessage()}") + } else { + throw new FailedToFormat(file.toString, e) + } + } + override def excluded(file: Path): Unit = log.debug(s"file excluded: $file")