You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If you have any errors in the Scalafmt configuration file, e.g. a mistype in an option name, the Scalafmt step will fail with a very unhelpful error message:
Caused by: java.lang.reflect.InvocationTargetException
at com.diffplug.spotless.scala.ScalaFmtStep.invokeNoArg(ScalaFmtStep.java:142)
at com.diffplug.spotless.scala.ScalaFmtStep.access$100(ScalaFmtStep.java:38)
at com.diffplug.spotless.scala.ScalaFmtStep$State.createFormat(ScalaFmtStep.java:130)
at com.diffplug.spotless.FormatterStepImpl$Standard.format(FormatterStepImpl.java:76)
at com.diffplug.spotless.FormatterStep$Strict.format(FormatterStep.java:76)
at com.diffplug.spotless.Formatter.compute(Formatter.java:230)
... 90 more
Caused by: java.util.NoSuchElementException: Either.right.value on Left
at scala.util.Either$RightProjection.get(Either.scala:453)
... 96 more
This is not a right way to do it: in Scala, proper handling would've looked like this:
config = either match {
caseLeft(e) =>// e is an error (maybe even a `Throwable`), log it somehow or wrap it into an exception and throw itcaseRight(r) => r // successful result
}
In Java, I guess something like this should work (without reflection):
Making the change you suggest is very possible but tedious with the reflection-based approach. An alternative approach is #524. Happy to merge a PR which uses either technique.
Summary
If you have any errors in the Scalafmt configuration file, e.g. a mistype in an option name, the Scalafmt step will fail with a very unhelpful error message:
Spotless configuration
build.gradle.kts
:.scalafmt.conf
:Thoughts
The reason why this happens is an unconditional call to
either.right.get
:spotless/lib/src/main/java/com/diffplug/spotless/scala/ScalaFmtStep.java
Line 130 in c007dba
This is not a right way to do it: in Scala, proper handling would've looked like this:
In Java, I guess something like this should work (without reflection):
Gradle version
6.1.1, but probably not relevant
Spotless version
3.26.1
OS
macOS 10.14.6
The text was updated successfully, but these errors were encountered: