mirror of
https://github.com/github/codeql.git
synced 2025-12-21 03:06:31 +01:00
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:
@@ -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()
|
||||
}
|
||||
|
||||
@@ -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())
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user