Kotlin: Catch all Throwables

We want to try to continue even if we hit a stack overflow or an
assertion error.
This commit is contained in:
Ian Lynagh
2022-03-08 17:22:59 +00:00
parent 8f929e2498
commit 84c7b2310a
2 changed files with 11 additions and 5 deletions

View File

@@ -54,7 +54,10 @@ class KotlinExtractorExtension(
override fun generate(moduleFragment: IrModuleFragment, pluginContext: IrPluginContext) {
try {
runExtractor(moduleFragment, pluginContext)
} catch(e: Exception) {
// We catch Throwable rather than Exception, as we want to
// continue trying to extract everything else even if we get a
// stack overflow or an assertion failure in one file.
} catch(e: Throwable) {
// If we get an exception at the top level, then we don't
// have many options. We just print it to stderr, and then
// return so the rest of the compilation can complete.
@@ -269,7 +272,10 @@ private fun doFile(
logger.warn("Failed to rename $trapTmpFile to $trapFile")
}
}
} catch (e: Exception) {
// We catch Throwable rather than Exception, as we want to
// continue trying to extract everything else even if we get a
// stack overflow or an assertion failure in one file.
} catch (e: Throwable) {
logger.error("Failed to extract '$srcFilePath'. Partial TRAP file location is $trapTmpFile", e)
fileExtractionProblems.setNonRecoverableProblem()
}

View File

@@ -166,7 +166,7 @@ open class Logger(val loggerBase: LoggerBase, open val tw: TrapWriter) {
fun trace(msg: String) {
loggerBase.trace(tw, msg)
}
fun trace(msg: String, exn: Exception) {
fun trace(msg: String, exn: Throwable) {
trace(msg + "\n" + exn.stackTraceToString())
}
fun debug(msg: String) {
@@ -180,7 +180,7 @@ open class Logger(val loggerBase: LoggerBase, open val tw: TrapWriter) {
fun warn(msg: String, extraInfo: String?) {
loggerBase.warn(tw, msg, extraInfo)
}
fun warn(msg: String, exn: Exception) {
fun warn(msg: String, exn: Throwable) {
warn(msg, exn.stackTraceToString())
}
fun warn(msg: String) {
@@ -193,7 +193,7 @@ open class Logger(val loggerBase: LoggerBase, open val tw: TrapWriter) {
fun error(msg: String) {
error(msg, null)
}
fun error(msg: String, exn: Exception) {
fun error(msg: String, exn: Throwable) {
error(msg, exn.stackTraceToString())
}
}