Skip to content

Commit 26c642d

Browse files
authored
Fix unknown compiler crash printing 'null' (#780)
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.
1 parent ccc3cb5 commit 26c642d

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

effekt/shared/src/main/scala/effekt/Compiler.scala

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,11 @@ trait Compiler[Executable] {
115115
* - Server / Driver to typecheck and report type errors in VSCode
116116
*/
117117
def runFrontend(source: Source)(using C: Context): Option[Module] =
118+
def getStackTrace(e: Throwable): String =
119+
val stringWriter = new java.io.StringWriter()
120+
e.printStackTrace(new java.io.PrintWriter(stringWriter))
121+
stringWriter.toString
122+
118123
try {
119124
val res = Frontend(source).map { res =>
120125
val mod = res.mod
@@ -128,15 +133,11 @@ trait Compiler[Executable] {
128133
None
129134
case e @ CompilerPanic(msg) =>
130135
C.report(msg)
131-
e.getStackTrace.foreach { line =>
132-
C.info(" at " + line)
133-
}
136+
C.info(getStackTrace(e))
134137
None
135138
case e =>
136-
C.info("Effekt Compiler Crash: " + e.getMessage)
137-
e.getStackTrace.foreach { line =>
138-
C.info(" at " + line)
139-
}
139+
C.info("Effekt Compiler Crash: " + e.toString)
140+
C.info(getStackTrace(e))
140141
None
141142
}
142143

0 commit comments

Comments
 (0)