Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

better error for external rules ran with old scalafix-cli version #1562

Merged
merged 1 commit into from
Mar 12, 2022

Conversation

bjaglin
Copy link
Collaborator

@bjaglin bjaglin commented Mar 12, 2022

Follows #1530

metaconfig-pprint brought by metaconfig-core 0.10.0 will not be available to external rules when classloaded by an old scalafix-cli version as the runtime scalafix-core and its dependencies are driven by scalafix-cli dependencies, not the rule dependencies.

We obviously have no control over old scalafix-cli versions, but since the reference to the potentially-missing type is from a macro-generated block, this wraps it to provide a more actionable error message.

@bjaglin
Copy link
Collaborator Author

bjaglin commented Mar 12, 2022

I tested to run a build of simulacrum-scalafix against this PR with a very old scalafix-cli and confirmed the presence of the error message

➜ cs launch --scala-version 2.12 ch.epfl.scala:::scalafix-cli:0.9.13 -M scalafix.cli.Cli -- --tool-classpath /home/brice/.ivy2/local/org.typelevel/simulacrum-scalafix_2.12/0.5.5-SNAPSHOT/jars/simulacrum-scalafix_2.12.jar --rules=ExpandPolymorphicLambdas && echo OK || echo KO
Exception in thread "main" java.util.ServiceConfigurationError: scalafix.v1.Rule: Provider org.typelevel.simulacrum.fix.TypeClassSupport could not be instantiated
	at java.base/java.util.ServiceLoader.fail(ServiceLoader.java:582)
	at java.base/java.util.ServiceLoader$ProviderImpl.newInstance(ServiceLoader.java:804)
	at java.base/java.util.ServiceLoader$ProviderImpl.get(ServiceLoader.java:722)
	at java.base/java.util.ServiceLoader$3.next(ServiceLoader.java:1395)
	at scala.collection.convert.Wrappers$JIteratorWrapper.next(Wrappers.scala:44)
	at scala.collection.Iterator.foreach(Iterator.scala:943)
	at scala.collection.Iterator.foreach$(Iterator.scala:943)
	at scala.collection.AbstractIterator.foreach(Iterator.scala:1431)
	at scala.collection.generic.Growable.$plus$plus$eq(Growable.scala:62)
	at scala.collection.generic.Growable.$plus$plus$eq$(Growable.scala:53)
	at scala.collection.mutable.ListBuffer.$plus$plus$eq(ListBuffer.scala:184)
	at scala.collection.mutable.ListBuffer.$plus$plus$eq(ListBuffer.scala:47)
	at scala.collection.TraversableOnce.to(TraversableOnce.scala:348)
	at scala.collection.TraversableOnce.to$(TraversableOnce.scala:346)
	at scala.collection.AbstractIterator.to(Iterator.scala:1431)
	at scala.collection.TraversableOnce.toList(TraversableOnce.scala:332)
	at scala.collection.TraversableOnce.toList$(TraversableOnce.scala:332)
	at scala.collection.AbstractIterator.toList(Iterator.scala:1431)
	at scalafix.internal.v1.Rules$.all(Rules.scala:101)
	at scalafix.v1.RuleDecoder$$anon$1.<init>(RuleDecoder.scala:99)
	at scalafix.v1.RuleDecoder$.decoder(RuleDecoder.scala:98)
	at scalafix.internal.v1.Args.ruleDecoder(Args.scala:243)
	at scalafix.internal.v1.Args.configuredRules(Args.scala:262)
	at scalafix.internal.v1.Args.$anonfun$validate$1(Args.scala:369)
	at metaconfig.Configured.andThen(Configured.scala:33)
	at scalafix.internal.v1.Args.validate(Args.scala:364)
	at scalafix.internal.v1.MainOps$.run(MainOps.scala:62)
	at scalafix.v1.Main$.run(Main.scala:32)
	at scalafix.v1.Main$.main(Main.scala:23)
	at scalafix.cli.Cli$.main(Cli.scala:9)
	at scalafix.cli.Cli.main(Cli.scala)
Caused by: java.lang.ExceptionInInitializerError
	at org.typelevel.simulacrum.fix.TypeClassSupport.<init>(TypeClassSupport.scala:25)
	at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
	at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
	at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
	at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:490)
	at java.base/java.util.ServiceLoader$ProviderImpl.newInstance(ServiceLoader.java:780)
	... 29 more
Caused by: java.lang.RuntimeException: Scalafix version 0.9.13 detected. Please upgrade to 0.9.34+51-19a0ea46-SNAPSHOT or later
	at org.typelevel.simulacrum.fix.TypeClassSupportConfig$.liftedTree1$1(TypeClassSupport.scala:17)
	at org.typelevel.simulacrum.fix.TypeClassSupportConfig$.<init>(TypeClassSupport.scala:17)
	at org.typelevel.simulacrum.fix.TypeClassSupportConfig$.<clinit>(TypeClassSupport.scala)
	... 35 more
Caused by: java.lang.NoClassDefFoundError: metaconfig/pprint/TPrintColors
	... 38 more
Caused by: java.lang.ClassNotFoundException: metaconfig.pprint.TPrintColors
	at java.base/java.net.URLClassLoader.findClass(URLClassLoader.java:476)
	at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:589)
	at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:522)
	... 38 more

metaconfig-pprint brought by metaconfig-core 0.10.0 will not be
available to external rules when classloaded by an old scalafix-cli
version as the runtime scalafix-core and its dependencies are driven by
scalafix-cli dependencies, not the rule dependencies.

We obviously have no control over old scalafix-cli versions, but since
the reference to the potentially-missing type is from a macro-generated
block, this wraps it to provide a more actionable error message.
@bjaglin bjaglin marked this pull request as ready for review March 12, 2022 15:50
@bjaglin bjaglin merged commit a83785c into scalacenter:main Mar 12, 2022
@bjaglin
Copy link
Collaborator Author

bjaglin commented Mar 12, 2022

Unfortunately, sbt-scalfix only keeps the first line of the exception, so this is not useful at all:

sbt:sbt-scalafix> scalafixAll
[error] (scalafixAll) scalafix.sbt.InvalidArgument: scalafix.v1.Rule: Provider org.typelevel.simulacrum.fix.TypeClassSupport could not be instantiated
[error] Total time: 5 s, completed Mar 13, 2022, 12:48:25 AM

Since sbt-scalafix will be updated before any external rule, I guess it's not really a problem. The expected added value of this PR will be on other clients lagging behind.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant