@@ -15,28 +15,35 @@ class ScalafmtCliReporter(options: CliOptions) extends ScalafmtReporter {
1515 private val exitCode = new AtomicReference (ExitCode .Ok )
1616
1717 def getExitCode : ExitCode = exitCode.get()
18+ private def updateExitCode (code : ExitCode ): Unit =
19+ if (! code.isOk) exitCode.getAndUpdate(ExitCode .merge(code, _))
1820
1921 override def error (file : Path , message : String ): Unit =
2022 if (! options.ignoreWarnings) {
2123 options.common.err.println(s " $message: $file" )
22- exitCode.getAndUpdate (ExitCode .merge( ExitCode . UnexpectedError , _) )
24+ updateExitCode (ExitCode .UnexpectedError )
2325 }
26+ override final def error (file : Path , e : Throwable ): Unit =
27+ updateExitCode(error(file)(e))
2428 @ tailrec
25- override final def error (file : Path , e : Throwable ): Unit = e match {
26- case WithCode (e, _) => error(file, e)
27- case _ : PositionException if ! options.ignoreWarnings =>
28- options.common.err.println(s " ${e.toString}: $file" )
29- exitCode.getAndUpdate(ExitCode .merge(ExitCode .ParseError , _))
30- case MisformattedFile (_, diff) =>
31- options.common.err.println(diff)
32- exitCode.getAndUpdate(ExitCode .merge(ExitCode .TestError , _))
33- case e : ScalafmtException => error(file, e.getCause)
34- case _ if e.getClass.getSimpleName.contains(" ScalafmtException" ) =>
35- error(file, e.getCause)
36- case _ if options.ignoreWarnings =>
29+ private [cli] final def error (file : Path )(e : Throwable ): ExitCode = e match {
30+ case e : MisformattedFile =>
31+ options.common.err.println(e.customMessage)
32+ ExitCode .TestError
33+ case _ : PositionException =>
34+ if (options.ignoreWarnings) ExitCode .Ok
35+ else {
36+ options.common.err.println(s " ${e.toString}: $file" )
37+ ExitCode .ParseError
38+ }
3739 case _ =>
38- new FailedToFormat (file.toString, e).printStackTrace(options.common.err)
39- exitCode.getAndUpdate(ExitCode .merge(ExitCode .UnexpectedError , _))
40+ val cause = e.getCause
41+ if (cause ne null ) error(file)(cause)
42+ else if (options.ignoreWarnings) ExitCode .Ok
43+ else {
44+ new FailedToFormat (file.toString, e).printStackTrace(options.common.err)
45+ ExitCode .UnexpectedError
46+ }
4047 }
4148
4249 override def excluded (file : Path ): Unit = options.common.debug
0 commit comments