Skip to content

Commit

Permalink
Fix unknown compiler crash printing 'null' (#780)
Browse files Browse the repository at this point in the history
Resolves the `Effect Compiler Crash: null` part of #760.
The actual problem there was that `e.getMessage` can return `null` and
it does for... _StackOverflowException_ 🥳.
Looking at the docs, it's recommended to use `e.toString`.

While I was at it, I modified stack trace printing, now we do it
properly by using `.printStackTrace`.

This is very related to #731, I just want to get this out quickly to
unblock other problems.
  • Loading branch information
jiribenes authored Jan 15, 2025
1 parent ccc3cb5 commit 26c642d
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions effekt/shared/src/main/scala/effekt/Compiler.scala
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,11 @@ trait Compiler[Executable] {
* - Server / Driver to typecheck and report type errors in VSCode
*/
def runFrontend(source: Source)(using C: Context): Option[Module] =
def getStackTrace(e: Throwable): String =
val stringWriter = new java.io.StringWriter()
e.printStackTrace(new java.io.PrintWriter(stringWriter))
stringWriter.toString

try {
val res = Frontend(source).map { res =>
val mod = res.mod
Expand All @@ -128,15 +133,11 @@ trait Compiler[Executable] {
None
case e @ CompilerPanic(msg) =>
C.report(msg)
e.getStackTrace.foreach { line =>
C.info(" at " + line)
}
C.info(getStackTrace(e))
None
case e =>
C.info("Effekt Compiler Crash: " + e.getMessage)
e.getStackTrace.foreach { line =>
C.info(" at " + line)
}
C.info("Effekt Compiler Crash: " + e.toString)
C.info(getStackTrace(e))
None
}

Expand Down

0 comments on commit 26c642d

Please sign in to comment.