From 17a189a24b2c96f63048fcb7572f0ce2443977d8 Mon Sep 17 00:00:00 2001 From: Ilya Chernikov Date: Wed, 19 Jul 2017 10:01:08 +0200 Subject: [PATCH] Improve logging and exception handling in the daemon --- .../org/jetbrains/kotlin/daemon/CompileServiceImpl.kt | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/compiler/daemon/src/org/jetbrains/kotlin/daemon/CompileServiceImpl.kt b/compiler/daemon/src/org/jetbrains/kotlin/daemon/CompileServiceImpl.kt index 8acedf8581c..b30d8d0ef01 100644 --- a/compiler/daemon/src/org/jetbrains/kotlin/daemon/CompileServiceImpl.kt +++ b/compiler/daemon/src/org/jetbrains/kotlin/daemon/CompileServiceImpl.kt @@ -234,7 +234,7 @@ class CompileServiceImpl( port = port.toString())) try { if (!runFile.createNewFile()) throw Exception("createNewFile returned false") - } catch (e: Exception) { + } catch (e: Throwable) { throw IllegalStateException("Unable to create run file '${runFile.absolutePath}'", e) } runFile.deleteOnExit() @@ -598,7 +598,7 @@ class CompileServiceImpl( try { body() } - catch (e: Exception) { + catch (e: Throwable) { System.err.println("Exception in timer thread: " + e.message) e.printStackTrace(System.err) log.log(Level.SEVERE, "Exception in timer thread", e) @@ -667,6 +667,7 @@ class CompileServiceImpl( ifAliveUnit { + log.info("initiate elections") val aliveWithOpts = walkDaemons(File(daemonOptions.runFilesPathOrDefault), compilerId, runFile, filter = { _, p -> p != port }, report = { _, msg -> log.info(msg) }).toList() val comparator = compareByDescending(DaemonJVMOptionsMemoryComparator(), { it.jvmOptions }) .thenBy(FileAgeComparator()) { it.runFile } @@ -682,7 +683,7 @@ class CompileServiceImpl( } daemon.scheduleShutdown(true) } - catch (e: Exception) { + catch (e: Throwable) { log.info("Cannot connect to a daemon, assuming dying ('${runFile.canonicalPath}'): ${e.message}") } } @@ -883,7 +884,7 @@ class CompileServiceImpl( return res } // TODO: consider possibilities to handle OutOfMemory - catch (e: Exception) { + catch (e: Throwable) { log.info("Error: $e") throw e } @@ -927,7 +928,7 @@ class CompileServiceImpl( try { body() } - catch (e: Exception) { + catch (e: Throwable) { log.log(Level.SEVERE, "Exception", e) CompileService.CallResult.Error(e.message ?: "unknown") }