From 6aa84732bf2d2f0dec886da4c1feb2e1456999af Mon Sep 17 00:00:00 2001 From: WarningImHack3r <43064022+WarningImHack3r@users.noreply.github.com> Date: Mon, 7 Oct 2024 19:53:16 +0200 Subject: [PATCH] Improve error submitter --- .../errorsubmitter/GitHubErrorReportSubmitter.kt | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/main/kotlin/com/github/warningimhack3r/intellijshadcnplugin/errorsubmitter/GitHubErrorReportSubmitter.kt b/src/main/kotlin/com/github/warningimhack3r/intellijshadcnplugin/errorsubmitter/GitHubErrorReportSubmitter.kt index 1965f1d..ce8d033 100644 --- a/src/main/kotlin/com/github/warningimhack3r/intellijshadcnplugin/errorsubmitter/GitHubErrorReportSubmitter.kt +++ b/src/main/kotlin/com/github/warningimhack3r/intellijshadcnplugin/errorsubmitter/GitHubErrorReportSubmitter.kt @@ -39,7 +39,7 @@ class GitHubErrorReportSubmitter : ErrorReportSubmitter() { ): Boolean { return try { // Base data - val event = if (events.isNotEmpty()) events.first() else null + val event = events.firstOrNull() val stackTrace = event?.throwableText ?: "" val simpleErrorMessage = if (event != null && !event.message.isNullOrEmpty()) { @@ -54,7 +54,7 @@ class GitHubErrorReportSubmitter : ErrorReportSubmitter() { var causedByLastIndex = -1 val splitStackTrace = stackTrace.split("\n") splitStackTrace.reversed().forEachIndexed { index, s -> - if (s.lowercase().startsWith("caused by")) { + if (s.startsWith("caused by", ignoreCase = true)) { causedByLastIndex = splitStackTrace.size - index return@forEachIndexed } @@ -77,10 +77,10 @@ class GitHubErrorReportSubmitter : ErrorReportSubmitter() { && !line.startsWith("at kotlinx.") && !line.startsWith("at com.intellij.") }.joinToString("\n"), - /*"device-os" to with(System.getProperty("os.name").lowercase()) { + /*"device-os" to with(System.getProperty("os.name")) { when { // Windows, macOS or Linux - startsWith("windows") -> "Windows" - startsWith("mac") -> "macOS" + startsWith("windows", ignoreCase = true) -> "Windows" + startsWith("mac", ignoreCase = true) -> "macOS" else -> "Linux" } },*/ // currently cannot be set (https://github.com/orgs/community/discussions/44983) @@ -184,7 +184,7 @@ class GitHubErrorReportSubmitter : ErrorReportSubmitter() { return IdeFocusManager.getGlobalInstance().lastFocusedFrame?.project ?: run { val projectManager = ProjectManager.getInstance() val openProjects = projectManager.openProjects - if (openProjects.isNotEmpty()) openProjects.first() else projectManager.defaultProject + openProjects.firstOrNull() ?: projectManager.defaultProject } } }