Skip to content

Report a crash from the compiler instead of hanging the compilation#2967

Merged
tgodzik merged 1 commit into
scalacenter:mainfrom
jozanek:fix/1434-compiler-crash-stacktrace
Jun 12, 2026
Merged

Report a crash from the compiler instead of hanging the compilation#2967
tgodzik merged 1 commit into
scalacenter:mainfrom
jozanek:fix/1434-compiler-crash-stacktrace

Conversation

@jozanek

@jozanek jozanek commented Jun 11, 2026

Copy link
Copy Markdown
Contributor

Fixes #1434

The original report asked for the complete stack trace when a compiler plugin crashes the compiler with a NoSuchMethodError. The reporting side was largely fixed in the meantime (since v1.5.12 the consumer of a failed compile result prints the whole trace), but reproducing the scenario revealed something worse: the compilation never finishes at all.

NoSuchMethodError is a LinkageError, which NonFatal treats as fatal: it escapes the monix task running the compilation and the result is never completed, leaving the client waiting forever. StackOverflowError and NoClassDefFoundError were already special-cased in BloopHighLevelCompiler, but every other LinkageError fell through, and the crash reporting was split between the catch sites and the consumer of the result, which printed the trace twice.

Now all fatal compiler crashes are wrapped in a new non-fatal bloop.CompilerCrash carrying type-specific advice, so the compilation fails normally through Result.Failed(..., Some(t)) and the consumer of the result reports the full stack trace exactly once:

Unexpected error when compiling b: bloop.CompilerCrash: The compiler crashed with a NoSuchMethodError. A compiler plugin or something else on the compiler classpath may be incompatible with the used Scala version
	at sbt.internal.inc.bloop.internal.BloopHighLevelCompiler.compileSources$1(...)
	...
Caused by: java.lang.NoSuchMethodError: boom
	at crash.CrashingPlugin$Component$$anon$1.apply(CrashingPlugin.scala:19)
	at scala.tools.nsc.Global$GlobalPhase.applyPhase(Global.scala:465)
	...

Notes

CompilerCrash is deliberately public in the bloop package even though it is just a transport between the compiler integration and the result reporting: the only instantiation site lives in sbt.internal.inc.bloop.internal, outside the bloop package hierarchy, so private[bloop] would not compile, and the class's fully-qualified name is the first line of the user-visible report, where bloop.CompilerCrash reads better than a sbt.internal.inc.* name.

@tgodzik tgodzik left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@tgodzik tgodzik merged commit 998594b into scalacenter:main Jun 12, 2026
12 of 13 checks passed
@jozanek jozanek deleted the fix/1434-compiler-crash-stacktrace branch June 12, 2026 22:30
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.

provide a complete stacktrace when the compiler crashes

2 participants