@@ -57,11 +57,27 @@ class KotlinExtractorExtension(
5757 // continue trying to extract everything else even if we get a
5858 // stack overflow or an assertion failure in one file.
5959 } catch (e: Throwable ) {
60- // If we get an exception at the top level, then we don't
61- // have many options. We just print it to stderr, and then
62- // return so the rest of the compilation can complete.
63- System .err.println (" CodeQL Kotlin extractor: Top-level exception." )
64- e.printStackTrace(System .err)
60+ // If we get an exception at the top level, then something's
61+ // gone very wrong. Don't try to be too fancy, but try to
62+ // log a simple message.
63+ val msg = " [ERROR] CodeQL Kotlin extractor: Top-level exception."
64+ // First, if we can find our log directory, then let's try
65+ // making a log file there:
66+ val extractorLogDir = System .getenv(" CODEQL_EXTRACTOR_JAVA_LOG_DIR" )
67+ if (extractorLogDir != null || extractorLogDir != " " ) {
68+ // We use a slightly different filename pattern compared
69+ // to normal logs. Just the existence of a `-top` log is
70+ // a sign that something's gone very wrong.
71+ val logFile = File .createTempFile(" kotlin-extractor-top." , " .log" , File (extractorLogDir))
72+ logFile.writeText(msg)
73+ // Now we've got that out, let's see if we can append a stack trace too
74+ logFile.appendText(e.stackTraceToString())
75+ } else {
76+ // We don't have much choice here except to print to
77+ // stderr and hope for the best.
78+ System .err.println (msg)
79+ e.printStackTrace(System .err)
80+ }
6581 }
6682 if (exitAfterExtraction) {
6783 exitProcess(0 )
0 commit comments