From 70d28d6e2ec3fdb9babe632d49c36fad6e7f683c Mon Sep 17 00:00:00 2001 From: hannibal2 <24389977+hannibal002@users.noreply.github.com> Date: Sun, 17 Mar 2024 11:41:27 +0100 Subject: Fix: OpenBrowser Crash (#1195) Co-authored-by: hannibal2 <24389977+hannibal00212@users.noreply.github.com> --- .../java/at/hannibal2/skyhanni/test/command/ErrorManager.kt | 11 +++++------ src/main/java/at/hannibal2/skyhanni/utils/OSUtils.kt | 11 +++++++++-- 2 files changed, 14 insertions(+), 8 deletions(-) (limited to 'src/main/java/at/hannibal2') diff --git a/src/main/java/at/hannibal2/skyhanni/test/command/ErrorManager.kt b/src/main/java/at/hannibal2/skyhanni/test/command/ErrorManager.kt index 16757d255..e7d0fa3cb 100644 --- a/src/main/java/at/hannibal2/skyhanni/test/command/ErrorManager.kt +++ b/src/main/java/at/hannibal2/skyhanni/test/command/ErrorManager.kt @@ -113,18 +113,17 @@ object ErrorManager { noStackTrace: Boolean, vararg extraData: Pair, ) { - val error = Error(message, throwable) - error.printStackTrace() - Minecraft.getMinecraft().thePlayer ?: return - if (!ignoreErrorCache) { val pair = if (throwable.stackTrace.isNotEmpty()) { - throwable.stackTrace[0].let { it.fileName!! to it.lineNumber } + throwable.stackTrace[0].let { (it.fileName ?: "") to it.lineNumber } } else message to 0 if (cache.contains(pair)) return cache.add(pair) } + Error(message, throwable).printStackTrace() + Minecraft.getMinecraft().thePlayer ?: return + val fullStackTrace: String val stackTrace: String @@ -175,7 +174,7 @@ object ErrorManager { private fun Throwable.getCustomStackTrace( fullStackTrace: Boolean, - parent: List = emptyList() + parent: List = emptyList(), ): List = buildList { add("Caused by ${this@getCustomStackTrace.javaClass.name}: $message") diff --git a/src/main/java/at/hannibal2/skyhanni/utils/OSUtils.kt b/src/main/java/at/hannibal2/skyhanni/utils/OSUtils.kt index 812bf085f..e209e0ce9 100644 --- a/src/main/java/at/hannibal2/skyhanni/utils/OSUtils.kt +++ b/src/main/java/at/hannibal2/skyhanni/utils/OSUtils.kt @@ -9,7 +9,9 @@ object OSUtils { @JvmStatic fun openBrowser(url: String) { - if (Desktop.isDesktopSupported() && Desktop.getDesktop().isSupported(Desktop.Action.BROWSE)) { + val desktopSupported = Desktop.isDesktopSupported() + val supportedActionBrowse = Desktop.getDesktop().isSupported(Desktop.Action.BROWSE) + if (desktopSupported && supportedActionBrowse) { try { Desktop.getDesktop().browse(URI(url)) } catch (e: IOException) { @@ -20,7 +22,12 @@ object OSUtils { } } else { copyToClipboard(url) - ErrorManager.skyHanniError("Cannot open website, web browser is not supported! Copied url to clipboard.") + ErrorManager.logErrorStateWithData( + "Cannot open website! Copied url to clipboard instead", "Web browser is not supported", + "url" to url, + "desktopSupported" to desktopSupported, + "supportedActionBrowse" to supportedActionBrowse, + ) } } -- cgit