From 33cbfa9751c3ef7a6babfcff9595782cbac5acae Mon Sep 17 00:00:00 2001 From: schroda <50052685+schroda@users.noreply.github.com> Date: Mon, 11 Mar 2024 00:00:54 +0100 Subject: [PATCH] Fix/electron launch error not logged (#895) * Log "Browser::openInBrowser" errors The error was never written to the log file. It was only visible in the console * Remove "printStackTrace" usage with logs --- .../main/kotlin/suwayomi/tachidesk/server/ServerSetup.kt | 2 +- .../main/kotlin/suwayomi/tachidesk/server/util/Browser.kt | 6 ++++-- .../kotlin/suwayomi/tachidesk/server/util/SystemTray.kt | 4 +++- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/server/src/main/kotlin/suwayomi/tachidesk/server/ServerSetup.kt b/server/src/main/kotlin/suwayomi/tachidesk/server/ServerSetup.kt index 6c1d99823..c3eada5bd 100644 --- a/server/src/main/kotlin/suwayomi/tachidesk/server/ServerSetup.kt +++ b/server/src/main/kotlin/suwayomi/tachidesk/server/ServerSetup.kt @@ -218,7 +218,7 @@ fun applicationSetup() { } } catch (e: Throwable) { // cover both java.lang.Exception and java.lang.Error - e.printStackTrace() + logger.error(e) { "Failed to create/remove SystemTray due to" } } }, ignoreInitialValue = false) diff --git a/server/src/main/kotlin/suwayomi/tachidesk/server/util/Browser.kt b/server/src/main/kotlin/suwayomi/tachidesk/server/util/Browser.kt index 1760c0eb2..9f9d7d452 100644 --- a/server/src/main/kotlin/suwayomi/tachidesk/server/util/Browser.kt +++ b/server/src/main/kotlin/suwayomi/tachidesk/server/util/Browser.kt @@ -8,9 +8,11 @@ package suwayomi.tachidesk.server.util * file, You can obtain one at https://mozilla.org/MPL/2.0/. */ import dorkbox.desktop.Desktop +import mu.KotlinLogging import suwayomi.tachidesk.server.serverConfig object Browser { + private val logger = KotlinLogging.logger { } private val electronInstances = mutableListOf() private fun getAppBaseUrl(): String { @@ -28,14 +30,14 @@ object Browser { electronInstances.add(ProcessBuilder(electronPath, appBaseUrl).start()) } catch (e: Throwable) { // cover both java.lang.Exception and java.lang.Error - e.printStackTrace() + logger.error(e) { "openInBrowser: failed to launch electron due to" } } } else { try { Desktop.browseURL(appBaseUrl) } catch (e: Throwable) { // cover both java.lang.Exception and java.lang.Error - e.printStackTrace() + logger.error(e) { "openInBrowser: failed to launch browser due to" } } } } diff --git a/server/src/main/kotlin/suwayomi/tachidesk/server/util/SystemTray.kt b/server/src/main/kotlin/suwayomi/tachidesk/server/util/SystemTray.kt index e000b261f..3c9672237 100644 --- a/server/src/main/kotlin/suwayomi/tachidesk/server/util/SystemTray.kt +++ b/server/src/main/kotlin/suwayomi/tachidesk/server/util/SystemTray.kt @@ -10,6 +10,7 @@ package suwayomi.tachidesk.server.util import dorkbox.systemTray.MenuItem import dorkbox.systemTray.SystemTray import dorkbox.util.CacheUtil +import mu.KotlinLogging import suwayomi.tachidesk.server.ServerConfig import suwayomi.tachidesk.server.generated.BuildConfig import suwayomi.tachidesk.server.serverConfig @@ -17,6 +18,7 @@ import suwayomi.tachidesk.server.util.Browser.openInBrowser import suwayomi.tachidesk.server.util.ExitCode.Success object SystemTray { + private val logger = KotlinLogging.logger { } private var instance: SystemTray? = null fun create() { @@ -60,7 +62,7 @@ object SystemTray { systemTray } catch (e: Exception) { - e.printStackTrace() + logger.error(e) { "create: failed to create SystemTray due to" } null } }