rules_scala
rules_scala copied to clipboard
Bad error for macro code with scala_library
This should fail since the user should use scala_macro_library
but we should probably not crash the worker since it makes it very hard to understand what's happening on CI.
Additionally maybe we should suggest to use scala_macro_library
Exception in thread "main" java.lang.ClassFormatError: Absent Code attribute in method that is not native or abstract in class file com/wix/Foo$
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:763)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:467)
at java.net.URLClassLoader.access$100(URLClassLoader.java:73)
at java.net.URLClassLoader$1.run(URLClassLoader.java:368)
at java.net.URLClassLoader$1.run(URLClassLoader.java:362)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:361)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:348)
at scala.reflect.macros.runtime.JavaReflectionRuntimes$JavaReflectionResolvers$class.resolveJavaReflectionRuntime(JavaReflectionRuntimes
.scala:16)
at scala.reflect.macros.runtime.MacroRuntimes$MacroRuntimeResolver.resolveJavaReflectionRuntime(MacroRuntimes.scala:52)
at scala.reflect.macros.runtime.MacroRuntimes$MacroRuntimeResolver.resolveRuntime(MacroRuntimes.scala:65)
at scala.reflect.macros.runtime.MacroRuntimes$$anonfun$standardMacroRuntime$3.apply(MacroRuntimes.scala:35)
at scala.reflect.macros.runtime.MacroRuntimes$$anonfun$standardMacroRuntime$3.apply(MacroRuntimes.scala:35)
at scala.collection.mutable.MapLike$class.getOrElseUpdate(MapLike.scala:194)
at scala.collection.mutable.AbstractMap.getOrElseUpdate(Map.scala:80)
at scala.reflect.macros.runtime.MacroRuntimes$class.standardMacroRuntime(MacroRuntimes.scala:35)
at scala.tools.nsc.Global$$anon$1.standardMacroRuntime(Global.scala:489)
at scala.tools.nsc.typechecker.AnalyzerPlugins$$anon$12.default(AnalyzerPlugins.scala:416)
at scala.tools.nsc.typechecker.AnalyzerPlugins$$anon$12.default(AnalyzerPlugins.scala:413)
at scala.tools.nsc.typechecker.AnalyzerPlugins$class.invoke(AnalyzerPlugins.scala:369)
at scala.tools.nsc.typechecker.AnalyzerPlugins$class.pluginsMacroRuntime(AnalyzerPlugins.scala:413)
at scala.tools.nsc.Global$$anon$1.pluginsMacroRuntime(Global.scala:489)
at scala.reflect.macros.runtime.MacroRuntimes$class.macroRuntime(MacroRuntimes.scala:22)
at scala.tools.nsc.Global$$anon$1.macroRuntime(Global.scala:489)
at scala.tools.nsc.typechecker.Macros$MacroExpander$$anonfun$expand$1.apply(Macros.scala:579)
at scala.tools.nsc.typechecker.Macros$MacroExpander$$anonfun$expand$1.apply(Macros.scala:573)
at scala.tools.nsc.Global.withInfoLevel(Global.scala:225)
at scala.tools.nsc.typechecker.Macros$MacroExpander.expand(Macros.scala:572)
at scala.tools.nsc.typechecker.Macros$MacroExpander.apply(Macros.scala:560)
at scala.tools.nsc.typechecker.Macros$class.standardMacroExpand(Macros.scala:724)
at scala.tools.nsc.Global$$anon$1.standardMacroExpand(Global.scala:489)
at scala.tools.nsc.typechecker.AnalyzerPlugins$$anon$10.default(AnalyzerPlugins.scala:400)
at scala.tools.nsc.typechecker.AnalyzerPlugins$$anon$10.default(AnalyzerPlugins.scala:397)
at scala.tools.nsc.typechecker.AnalyzerPlugins$class.invoke(AnalyzerPlugins.scala:369)
at scala.tools.nsc.typechecker.AnalyzerPlugins$class.pluginsMacroExpand(AnalyzerPlugins.scala:397)
at scala.tools.nsc.Global$$anon$1.pluginsMacroExpand(Global.scala:489)
at scala.tools.nsc.typechecker.Macros$class.macroExpand(Macros.scala:717)
at scala.tools.nsc.Global$$anon$1.macroExpand(Global.scala:489)
at scala.tools.nsc.typechecker.Typers$Typer.vanillaAdapt$1(Typers.scala:1111)
at scala.tools.nsc.typechecker.Typers$Typer.adapt(Typers.scala:1166)
at scala.tools.nsc.typechecker.Typers$Typer.runTyper$1(Typers.scala:5437)
at scala.tools.nsc.typechecker.Typers$Typer.scala$tools$nsc$typechecker$Typers$Typer$$typedInternal(Typers.scala:5450)
at scala.tools.nsc.typechecker.Typers$Typer.body$2(Typers.scala:5397)
at scala.tools.nsc.typechecker.Typers$Typer.typed(Typers.scala:5401)
at scala.tools.nsc.typechecker.Typers$Typer$$anonfun$adaptToImplicitMethod$1$1$$anonfun$apply$5.apply(Typers.scala:828)
at scala.tools.nsc.typechecker.Typers$Typer$$anonfun$adaptToImplicitMethod$1$1$$anonfun$apply$5.apply(Typers.scala:825)
at scala.tools.nsc.typechecker.Typers$Typer.silent(Typers.scala:693)
at scala.tools.nsc.typechecker.Typers$Typer.adaptToImplicitMethod$1(Typers.scala:823)
at scala.tools.nsc.typechecker.Typers$Typer.adapt(Typers.scala:1162)
at scala.tools.nsc.typechecker.Typers$Typer.runTyper$1(Typers.scala:5437)
at scala.tools.nsc.typechecker.Typers$Typer.scala$tools$nsc$typechecker$Typers$Typer$$typedInternal(Typers.scala:5450)
at scala.tools.nsc.typechecker.Typers$Typer.body$2(Typers.scala:5397)
at scala.tools.nsc.typechecker.Typers$Typer.typed(Typers.scala:5401)
at scala.tools.nsc.typechecker.Typers$Typer.typedArg(Typers.scala:3163)
at scala.tools.nsc.typechecker.PatternTypers$PatternTyper$class.typedArgWithFormal$1(PatternTypers.scala:112)
at scala.tools.nsc.typechecker.PatternTypers$PatternTyper$$anonfun$2.apply(PatternTypers.scala:115)
at scala.tools.nsc.typechecker.PatternTypers$PatternTyper$$anonfun$2.apply(PatternTypers.scala:115)
at scala.runtime.Tuple2Zipped$$anonfun$map$extension$1.apply(Tuple2Zipped.scala:46)
at scala.runtime.Tuple2Zipped$$anonfun$map$extension$1.apply(Tuple2Zipped.scala:44)
at scala.collection.immutable.List.foreach(List.scala:392)
at scala.runtime.Tuple2Zipped$.map$extension(Tuple2Zipped.scala:44)
at scala.tools.nsc.typechecker.PatternTypers$PatternTyper$class.typedArgsForFormals(PatternTypers.scala:115)
at scala.tools.nsc.typechecker.Typers$Typer.typedArgsForFormals(Typers.scala:111)
at scala.tools.nsc.typechecker.Typers$Typer.scala$tools$nsc$typechecker$Typers$Typer$$handleMonomorphicCall$1(Typers.scala:3469)
at scala.tools.nsc.typechecker.Typers$Typer.doTypedApply(Typers.scala:3494)
at scala.tools.nsc.typechecker.Typers$Typer$$anonfun$98.apply(Typers.scala:4495)
at scala.tools.nsc.typechecker.Typers$Typer$$anonfun$98.apply(Typers.scala:4495)
at scala.tools.nsc.typechecker.Typers$Typer.silent(Typers.scala:693)
at scala.tools.nsc.typechecker.Typers$Typer.tryTypedApply$1(Typers.scala:4495)
at scala.tools.nsc.typechecker.Typers$Typer.normalTypedApply$1(Typers.scala:4578)
at scala.tools.nsc.typechecker.Typers$Typer.typedApply$1(Typers.scala:4608)
at scala.tools.nsc.typechecker.Typers$Typer.typedInAnyMode$1(Typers.scala:5370)
at scala.tools.nsc.typechecker.Typers$Typer.typed1(Typers.scala:5387)
at scala.tools.nsc.typechecker.Typers$Typer.runTyper$1(Typers.scala:5423)
at scala.tools.nsc.typechecker.Typers$Typer.scala$tools$nsc$typechecker$Typers$Typer$$typedInternal(Typers.scala:5450)
at scala.tools.nsc.typechecker.Typers$Typer.body$2(Typers.scala:5397)
at scala.tools.nsc.typechecker.Typers$Typer.typed(Typers.scala:5401)
at scala.tools.nsc.typechecker.Typers$Typer.typedQualifier(Typers.scala:5501)
at scala.tools.nsc.typechecker.Typers$Typer.typedQualifier(Typers.scala:5507)
at scala.tools.nsc.typechecker.Typers$Typer.typedSelectOrSuperCall$1(Typers.scala:4839)
at scala.tools.nsc.typechecker.Typers$Typer.typedInAnyMode$1(Typers.scala:5371)
at scala.tools.nsc.typechecker.Typers$Typer.typed1(Typers.scala:5387)
at scala.tools.nsc.typechecker.Typers$Typer.runTyper$1(Typers.scala:5423)
at scala.tools.nsc.typechecker.Typers$Typer.scala$tools$nsc$typechecker$Typers$Typer$$typedInternal(Typers.scala:5450)
at scala.tools.nsc.typechecker.Typers$Typer.body$2(Typers.scala:5397)
at scala.tools.nsc.typechecker.Typers$Typer.typed(Typers.scala:5401)
at scala.tools.nsc.typechecker.Typers$Typer$$anonfun$102.apply(Typers.scala:4559)
at scala.tools.nsc.typechecker.Typers$Typer$$anonfun$102.apply(Typers.scala:4559)
at scala.tools.nsc.typechecker.Typers$Typer.silent(Typers.scala:680)
at scala.tools.nsc.typechecker.Typers$Typer.normalTypedApply$1(Typers.scala:4558)
at scala.tools.nsc.typechecker.Typers$Typer.typedApply$1(Typers.scala:4608)
at scala.tools.nsc.typechecker.Typers$Typer.typedInAnyMode$1(Typers.scala:5370)
at scala.tools.nsc.typechecker.Typers$Typer.typed1(Typers.scala:5387)
at scala.tools.nsc.typechecker.Typers$Typer.runTyper$1(Typers.scala:5423)
at scala.tools.nsc.typechecker.Typers$Typer.scala$tools$nsc$typechecker$Typers$Typer$$typedInternal(Typers.scala:5450)
at scala.tools.nsc.typechecker.Typers$Typer.body$2(Typers.scala:5397)
at scala.tools.nsc.typechecker.Typers$Typer.typed(Typers.scala:5401)
at scala.tools.nsc.typechecker.Typers$Typer.typedByValueExpr(Typers.scala:5481)
Yeah. We can look for code absent and if we hit that it must be due to a macro. Would be great to just give that error.
I got a similar error when a dependency for a scala macro was missing, very hard to track down where it occured. In general, scala macros can fail for whatever reason, and bazel need to be able to catch such errors.
java.lang.RuntimeException: Build failed
at io.bazel.rulesscala.scalac.ScalacProcessor.compileScalaSources(ScalacProcessor.java:242)
at io.bazel.rulesscala.scalac.ScalacProcessor.processRequest(ScalacProcessor.java:67)
at io.bazel.rulesscala.worker.GenericWorker.run(GenericWorker.java:114)
at io.bazel.rulesscala.scalac.ScalaCInvoker.main(ScalaCInvoker.java:41)
error: java.lang.NoClassDefFoundError: magnolia/Magnolia$
at com.spotify.scio.coders.CoderMacros$.wrappedCoder(CoderMacros.scala:135)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at scala.reflect.macros.runtime.JavaReflectionRuntimes$JavaReflectionResolvers.$anonfun$resolveJavaReflectionRuntime$4(JavaReflectionRuntimes.scala:34)
In this case I guess scio needs to have a macro_library dependency on magnolia.
This tool: https://github.com/johnynek/bazel-deps solves this problem by using scala_import (a function defined in this repo) in order to make sure scala macros are on the compilation class path.
We could possibly detect this error due to where the exception is thrown and give a better error message, but we can’t change the dependencies in bazel: they are statically defined in the BUILD files. The best we could do is make a tool to automatically generate builds.
I was able to solve this particular problem.
But what I want to have fixed here is that bazel does not report where (in what source or BUILD file) the error occurs, making troubleshooting harder. I don't expect bazel to magically solve the problem for me, just point out where the problem occured.
this isn't bazel, this is scalac. We are invoking scalac and it is throwing the NoClassDefFoundError
. Bazel is something like a very fancy make
. There is no way bazel can solve the issue. We need the underlying tool, in this case scalac, or another tool to compile scala, to point out more information.
@johnynek are you sure? We’re running scalac ourselves so I think we can catch the error, inspect it and rethrow with a clearer message. Wdyt? On Thu, 24 Jan 2019 at 12:08 P. Oscar Boykin [email protected] wrote:
this isn't bazel, this is scalac. We are invoking scalac and it is throwing the NoClassDefFoundError. Bazel is something like a very fancy make. There is no way bazel can solve the issue. We need the underlying tool, in this case scalac, or another tool to compile scala, to point out more information.
— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/bazelbuild/rules_scala/issues/366#issuecomment-457276959, or mute the thread https://github.com/notifications/unsubscribe-auth/ABUIF2S1pD9HSDFxsFihRrKnEcgPjRh4ks5vGeh6gaJpZM4RCVWF .
@ittaiz as I mentioned here: https://github.com/bazelbuild/rules_scala/issues/366#issuecomment-457259448 yes we could do that, but he replied that we wanted to know what source we are in, but we can’t get that from the generic error thrown. Bazel already reports which build target fails. We can make it a little prettier but a huge improvement that I can see without scalac improving.
Bazel already reports which build target fails.
No, it does not for me. At least not when running build -k
.
@mikaelstaldal do you recall how you fixed this issue? I've just run into it myself..
Very high level- you probably have a target (internal or external) which has a macro and is defined as a scala_library. It needs to be defined as a scala_macro_library.
Using scala_macro_library
works. Confirmed. Thank you!