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

When ScalacWorker fails during macro evaluation, errors are not made available in build log #1488

Closed
thirtyseven opened this issue Mar 28, 2023 · 3 comments · Fixed by #1489

Comments

@thirtyseven
Copy link
Contributor

thirtyseven commented Mar 28, 2023

When compiling a scala_library that requires a macro expansion, and there is a user error in that macro, the entire scalac process will crash, resulting in a Bazel error like this:

ERROR: /Users/tkaplan/<redacted>:3:14: scala @//<redacted> failed: Worker process did not return a WorkResponse:

---8<---8<--- Start of log snippet, file at /private/var/tmp/_bazel_tkaplan/fa1bc4e61b191b698b582e9d142cb714/bazel-workers/worker-6-Scalac.log ---8<---8<---
[... truncated ...]
cros$MacroExpander.apply(Macros.scala:609)
	at scala.tools.nsc.typechecker.Macros.standardMacroExpand(Macros.scala:784)
	at scala.tools.nsc.typechecker.Macros.standardMacroExpand$(Macros.scala:782)
	at scala.tools.nsc.Global$$anon$5.standardMacroExpand(Global.scala:482)
	at scala.tools.nsc.typechecker.AnalyzerPlugins$$anon$10.default(AnalyzerPlugins.scala:457)
	at scala.tools.nsc.typechecker.AnalyzerPlugins$$anon$10.default(AnalyzerPlugins.scala:454)
	at scala.tools.nsc.typechecker.AnalyzerPlugins.invoke(AnalyzerPlugins.scala:411)
	at scala.tools.nsc.typechecker.AnalyzerPlugins.pluginsMacroExpand(AnalyzerPlugins.scala:454)
	at scala.tools.nsc.typechecker.AnalyzerPlugins.pluginsMacroExpand$(AnalyzerPlugins.scala:454)
	at scala.tools.nsc.Global$$anon$5.pluginsMacroExpand(Global.scala:482)

There are several reasons why this isn't very user-friendly:

  1. The actual reason for the error is in the truncated part of the stack trace (in this case, it was a NoSuchMethodError caused by mixing Scala 2.11 and 2.12 libs)
  2. If the build is happening on CI, getting the worker-n-Scalac.log file can be difficult
  3. The error won't be sent as part of the BES to any BES viewers like BuildBuddy

Maybe the ScalacWorker implementation should try to catch unchecked exceptions and determine if they are the result of macro expansion, rather than crashing.

Full worker log:
worker-6-Scalac.log

@johnynek
Copy link
Member

if you have time to send a test that reproduces this issue it would be helpful.

I thought we used to handle nonfatal exceptions, but maybe I'm misremembering.

@thirtyseven
Copy link
Contributor Author

I have a PR that fixes this for our case (#1489), it will take me a little longer to actually extract a repro that I can share.

@thirtyseven
Copy link
Contributor Author

@johnynek Linked PR has an E2E test that reproduces the issue

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 a pull request may close this issue.

2 participants