From 6bf58ce13cabf3e7c206b1f9158f534950ea25d8 Mon Sep 17 00:00:00 2001 From: Thomas Schouten Date: Sun, 10 Nov 2024 21:05:43 +0100 Subject: [PATCH 1/2] Shorten long stacktraces before submitting --- CHANGELOG.md | 1 + .../texifyidea/LatexErrorReportSubmitter.kt | 24 ++++++- .../util/LatexErrorReportSubmitterTest.kt | 67 +++++++++++++++++++ 3 files changed, 90 insertions(+), 2 deletions(-) create mode 100644 test/nl/hannahsten/texifyidea/util/LatexErrorReportSubmitterTest.kt diff --git a/CHANGELOG.md b/CHANGELOG.md index 265159fdf..a8b080e0c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ * Add setting to disable auto-import of bibtex entries from remote libraries ### Fixed +* Improve error report submitter for long stacktraces * Fix exception #3557 if using bibtex structure view when bibtex file type is reassignd to plain text ## [0.9.8] diff --git a/src/nl/hannahsten/texifyidea/LatexErrorReportSubmitter.kt b/src/nl/hannahsten/texifyidea/LatexErrorReportSubmitter.kt index 726adba23..94cbc6680 100644 --- a/src/nl/hannahsten/texifyidea/LatexErrorReportSubmitter.kt +++ b/src/nl/hannahsten/texifyidea/LatexErrorReportSubmitter.kt @@ -81,10 +81,18 @@ class LatexErrorReportSubmitter : ErrorReportSubmitter() { ?: event?.message ?: "Crash Report: " val body = event?.throwableText ?: "Please paste the full stacktrace from the IDEA error popup." + // In some cases, very long stacktraces can refer to TeXiFy code only at the bottom (after 7000 characters), but we do want to submit this information, so we trim the middle part of the stacktrace + val maximumUrlSize = 6000 + val smallBody = if ("at nl.hannahsten.texifyidea" in body && "at nl.hannahsten.texifyidea" !in body.take(maximumUrlSize)) { + Util.filterInterestingLines(body) + } + else { + body + } val builder = StringBuilder(ISSUE_URL) try { - builder.append(URLEncoder.encode(title, ENCODING)) + builder.append(URLEncoder.encode(title.take(500), ENCODING)) builder.append("&body=") val applicationInfo = ApplicationInfo.getInstance().let { "${it.fullApplicationName} (build ${it.build})" } @@ -94,7 +102,7 @@ class LatexErrorReportSubmitter : ErrorReportSubmitter() { builder.append(URLEncoder.encode("### TeXiFy IDEA version\n${Util.currentVersion}\n\n", ENCODING)) builder.append(URLEncoder.encode("### Description\n", ENCODING)) builder.append(URLEncoder.encode(additionalInfo ?: "\n", ENCODING)) - builder.append(URLEncoder.encode("\n\n### Stacktrace\n```\n${body.take(6000)}\n```", ENCODING)) + builder.append(URLEncoder.encode("\n\n### Stacktrace\n```\n${smallBody.take(6000)}\n```", ENCODING)) } catch (e: UnsupportedEncodingException) { consumer.consume( @@ -149,6 +157,18 @@ class LatexErrorReportSubmitter : ErrorReportSubmitter() { val currentVersion by lazy { PluginManagerCore.getPlugin(PluginId.getId("nl.rubensten.texifyidea"))?.version } + + /** + * If the stacktrace is too long, collect lines referring to TeXiFy only. + */ + fun filterInterestingLines(body: String): String { + val lines = body.split("\n").filter { it.isNotBlank() } + val texifyLines = lines.mapIndexedNotNull { i: Int, line: String -> if ("nl.hannahsten.texifyidea" in line || "Caused by:" in line) i else null } + val interestingLines = ((0..10).toSet() + texifyLines.flatMap { listOf(it - 1, it, it + 1) }.toSet()).toList().sorted() + return interestingLines.foldIndexed("") { i, stacktrace, lineIndex -> + stacktrace + (if (i > 0 && interestingLines[i - 1] < lineIndex - 1) "\n (...)" else "") + "\n" + lines.getOrElse(lineIndex) { "" }.take(500) + }.trim() + } } companion object { diff --git a/test/nl/hannahsten/texifyidea/util/LatexErrorReportSubmitterTest.kt b/test/nl/hannahsten/texifyidea/util/LatexErrorReportSubmitterTest.kt new file mode 100644 index 000000000..316844ddd --- /dev/null +++ b/test/nl/hannahsten/texifyidea/util/LatexErrorReportSubmitterTest.kt @@ -0,0 +1,67 @@ +package nl.hannahsten.texifyidea.util + +import nl.hannahsten.texifyidea.LatexErrorReportSubmitter +import org.junit.Assert.assertEquals +import org.junit.Test + +class LatexErrorReportSubmitterTest { + + @Test + fun testLongStacktrace() { + val stacktrace = """ + com.intellij.diagnostic.PluginException: Cannot create extension (class=nl.hannahsten.texifyidea.index.file.LatexExternalEnvironmentIndex) [Plugin: nl.rubensten.texifyidea] + at com.intellij.serviceContainer.ComponentManagerImpl.createError(ComponentManagerImpl.kt:980) + at com.intellij.openapi.extensions.impl.XmlExtensionAdapter.doCreateInstance(XmlExtensionAdapter.kt:73) + at com.intellij.openapi.extensions.impl.XmlExtensionAdapter.createInstance(XmlExtensionAdapter.kt:33) + at com.intellij.openapi.extensions.impl.ExtensionPointImpl.processAdapter(ExtensionPointImpl.kt:403) + at com.intellij.openapi.extensions.impl.ExtensionPointImpl.createExtensionInstances(ExtensionPointImpl.kt:376) + at com.intellij.openapi.extensions.impl.ExtensionPointImpl.getExtensionList(ExtensionPointImpl.kt:222) + at com.intellij.openapi.extensions.ExtensionPointName.getExtensionList(ExtensionPointName.kt:54) + at com.intellij.indexing.shared.platform.api.IdeSharedIndexesState.(IdeSharedIndexesState.java:38) + at nl.hannahsten.texifyidea.settings.codestyle.LatexCodeStyleSettingsProvider.createCustomSettings(LatexCodeStyleSettingsProvider.kt:21) + at nl.hannahsten.texifyidea.settings.codestyle.LatexCodeStyleSettingsProvider.createCustomSettings(LatexCodeStyleSettingsProvider.kt:19) + at com.intellij.psi.codeStyle.CustomCodeStyleSettingsManager.addCustomSettings(CustomCodeStyleSettingsManager.java:32) + at com.intellij.indexing.shared.platform.api.SharedIndexInfrastructureVersion.getIdeVersion(SharedIndexInfrastructureVersion.java:68) + at com.intellij.indexing.shared.platform.impl.SharedIndexStorageUtil.openFileBasedIndexChunks(SharedIndexStorageUtil.java:54) + at nl.hannahsten.texifyidea.settings.codestyle.LatexCodeStyleSettingsProvider.createCustomSettings(LatexCodeStyleSettingsProvider.kt:21) + at com.intellij.indexing.shared.platform.impl.SharedIndexChunkConfigurationImpl.openFileBasedIndexChunk(SharedIndexChunkConfigurationImpl.java:657) + at com.intellij.indexing.shared.platform.impl.SharedIndexChunkConfigurationImpl.registerChunk(SharedIndexChunkConfigurationImpl.java:618) + at com.intellij.indexing.shared.platform.impl.SharedIndexChunkConfigurationImpl.openChunkForProject(SharedIndexChunkConfigurationImpl.java:484) + Caused by: java.util.concurrent.ExecutionException: java.lang.InterruptedException + at java.base/java.util.concurrent.CompletableFuture.reportGet(CompletableFuture.java:396) + at java.base/java.util.concurrent.CompletableFuture.get(CompletableFuture.java:2096) + at org.jetbrains.concurrency.AsyncPromise.get(AsyncPromise.kt:51) + at org.jetbrains.concurrency.AsyncPromise.blockingGet(AsyncPromise.kt:130) + at nl.hannahsten.texifyidea.settings.codestyle.LatexCodeStyleSettingsProvider.createCustomSettings(LatexCodeStyleSettingsProvider.kt:21) + at nl.hannahsten.texifyidea.settings.codestyle.LatexCodeStyleSettingsProvider.createCustomSettings(LatexCodeStyleSettingsProvider.kt:19) + """.trimIndent() + val trimmedStacktrace = LatexErrorReportSubmitter.Util.filterInterestingLines(stacktrace) + val expected = """ + com.intellij.diagnostic.PluginException: Cannot create extension (class=nl.hannahsten.texifyidea.index.file.LatexExternalEnvironmentIndex) [Plugin: nl.rubensten.texifyidea] + at com.intellij.serviceContainer.ComponentManagerImpl.createError(ComponentManagerImpl.kt:980) + at com.intellij.openapi.extensions.impl.XmlExtensionAdapter.doCreateInstance(XmlExtensionAdapter.kt:73) + at com.intellij.openapi.extensions.impl.XmlExtensionAdapter.createInstance(XmlExtensionAdapter.kt:33) + at com.intellij.openapi.extensions.impl.ExtensionPointImpl.processAdapter(ExtensionPointImpl.kt:403) + at com.intellij.openapi.extensions.impl.ExtensionPointImpl.createExtensionInstances(ExtensionPointImpl.kt:376) + at com.intellij.openapi.extensions.impl.ExtensionPointImpl.getExtensionList(ExtensionPointImpl.kt:222) + at com.intellij.openapi.extensions.ExtensionPointName.getExtensionList(ExtensionPointName.kt:54) + at com.intellij.indexing.shared.platform.api.IdeSharedIndexesState.(IdeSharedIndexesState.java:38) + at nl.hannahsten.texifyidea.settings.codestyle.LatexCodeStyleSettingsProvider.createCustomSettings(LatexCodeStyleSettingsProvider.kt:21) + at nl.hannahsten.texifyidea.settings.codestyle.LatexCodeStyleSettingsProvider.createCustomSettings(LatexCodeStyleSettingsProvider.kt:19) + at com.intellij.psi.codeStyle.CustomCodeStyleSettingsManager.addCustomSettings(CustomCodeStyleSettingsManager.java:32) + (...) + at com.intellij.indexing.shared.platform.impl.SharedIndexStorageUtil.openFileBasedIndexChunks(SharedIndexStorageUtil.java:54) + at nl.hannahsten.texifyidea.settings.codestyle.LatexCodeStyleSettingsProvider.createCustomSettings(LatexCodeStyleSettingsProvider.kt:21) + at com.intellij.indexing.shared.platform.impl.SharedIndexChunkConfigurationImpl.openFileBasedIndexChunk(SharedIndexChunkConfigurationImpl.java:657) + (...) + at com.intellij.indexing.shared.platform.impl.SharedIndexChunkConfigurationImpl.openChunkForProject(SharedIndexChunkConfigurationImpl.java:484) + Caused by: java.util.concurrent.ExecutionException: java.lang.InterruptedException + at java.base/java.util.concurrent.CompletableFuture.reportGet(CompletableFuture.java:396) + (...) + at org.jetbrains.concurrency.AsyncPromise.blockingGet(AsyncPromise.kt:130) + at nl.hannahsten.texifyidea.settings.codestyle.LatexCodeStyleSettingsProvider.createCustomSettings(LatexCodeStyleSettingsProvider.kt:21) + at nl.hannahsten.texifyidea.settings.codestyle.LatexCodeStyleSettingsProvider.createCustomSettings(LatexCodeStyleSettingsProvider.kt:19) + """.trimIndent() + assertEquals(expected, trimmedStacktrace) + } +} \ No newline at end of file From 06ecde24f63a065564e55e52489a9e5ca58955ce Mon Sep 17 00:00:00 2001 From: Thomas Schouten Date: Thu, 14 Nov 2024 09:25:45 +0100 Subject: [PATCH 2/2] Improve logging for LatexIncorrectSectionNestingInspection --- .../latex/typesetting/LatexIncorrectSectionNestingInspection.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/nl/hannahsten/texifyidea/inspections/latex/typesetting/LatexIncorrectSectionNestingInspection.kt b/src/nl/hannahsten/texifyidea/inspections/latex/typesetting/LatexIncorrectSectionNestingInspection.kt index 34553ce2f..edb3ed417 100644 --- a/src/nl/hannahsten/texifyidea/inspections/latex/typesetting/LatexIncorrectSectionNestingInspection.kt +++ b/src/nl/hannahsten/texifyidea/inspections/latex/typesetting/LatexIncorrectSectionNestingInspection.kt @@ -41,7 +41,7 @@ open class LatexIncorrectSectionNestingInspection : TexifyInspectionBase() { .sortedBy { it.textOffset } .zipWithNext() .filter { (first, second) -> - first.commandName() in (commandToForbiddenPredecessors[second.commandName()] ?: error("Unexpected command")) + first.commandName() in (commandToForbiddenPredecessors[second.commandName()] ?: error("Unexpected command ${second.commandName()} after ${first.commandName()}")) } .map { manager.createProblemDescriptor(