Skip to content

Commit 668fba6

Browse files
authored
Merge pull request #3740 from Hannah-Sten/long-crash-report
Shorten long stacktraces before submitting
2 parents eb552bb + 1346ec5 commit 668fba6

File tree

4 files changed

+91
-4
lines changed

4 files changed

+91
-4
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
### Added
66

77
### Fixed
8+
* Improve error report submitter for long stacktraces
89

910
## [0.9.9-alpha.4] - 2024-11-13
1011

@@ -49,7 +50,6 @@
4950
* Add setting to disable auto-import of bibtex entries from remote libraries
5051

5152
### Fixed
52-
5353
* Fix exception #3557 if using bibtex structure view when bibtex file type is reassignd to plain text
5454
* Avoid referencing obsolete psifiles, fix exception #3635
5555

src/nl/hannahsten/texifyidea/LatexErrorReportSubmitter.kt

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,10 +81,18 @@ class LatexErrorReportSubmitter : ErrorReportSubmitter() {
8181
?: event?.message
8282
?: "Crash Report: <Fill in title>"
8383
val body = event?.throwableText ?: "Please paste the full stacktrace from the IDEA error popup."
84+
// 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
85+
val maximumUrlSize = 6000
86+
val smallBody = if ("at nl.hannahsten.texifyidea" in body && "at nl.hannahsten.texifyidea" !in body.take(maximumUrlSize)) {
87+
Util.filterInterestingLines(body)
88+
}
89+
else {
90+
body
91+
}
8492

8593
val builder = StringBuilder(ISSUE_URL)
8694
try {
87-
builder.append(URLEncoder.encode(title, ENCODING))
95+
builder.append(URLEncoder.encode(title.take(500), ENCODING))
8896
builder.append("&body=")
8997

9098
val applicationInfo = ApplicationInfo.getInstance().let { "${it.fullApplicationName} (build ${it.build})" }
@@ -94,7 +102,7 @@ class LatexErrorReportSubmitter : ErrorReportSubmitter() {
94102
builder.append(URLEncoder.encode("### TeXiFy IDEA version\n${Util.currentVersion}\n\n", ENCODING))
95103
builder.append(URLEncoder.encode("### Description\n", ENCODING))
96104
builder.append(URLEncoder.encode(additionalInfo ?: "\n", ENCODING))
97-
builder.append(URLEncoder.encode("\n\n### Stacktrace\n```\n${body.take(6000)}\n```", ENCODING))
105+
builder.append(URLEncoder.encode("\n\n### Stacktrace\n```\n${smallBody.take(6000)}\n```", ENCODING))
98106
}
99107
catch (e: UnsupportedEncodingException) {
100108
consumer.consume(
@@ -149,6 +157,18 @@ class LatexErrorReportSubmitter : ErrorReportSubmitter() {
149157
val currentVersion by lazy {
150158
PluginManagerCore.getPlugin(PluginId.getId("nl.rubensten.texifyidea"))?.version
151159
}
160+
161+
/**
162+
* If the stacktrace is too long, collect lines referring to TeXiFy only.
163+
*/
164+
fun filterInterestingLines(body: String): String {
165+
val lines = body.split("\n").filter { it.isNotBlank() }
166+
val texifyLines = lines.mapIndexedNotNull { i: Int, line: String -> if ("nl.hannahsten.texifyidea" in line || "Caused by:" in line) i else null }
167+
val interestingLines = ((0..10).toSet() + texifyLines.flatMap { listOf(it - 1, it, it + 1) }.toSet()).toList().sorted()
168+
return interestingLines.foldIndexed("") { i, stacktrace, lineIndex ->
169+
stacktrace + (if (i > 0 && interestingLines[i - 1] < lineIndex - 1) "\n (...)" else "") + "\n" + lines.getOrElse(lineIndex) { "" }.take(500)
170+
}.trim()
171+
}
152172
}
153173

154174
companion object {

src/nl/hannahsten/texifyidea/inspections/latex/typesetting/LatexIncorrectSectionNestingInspection.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ open class LatexIncorrectSectionNestingInspection : TexifyInspectionBase() {
4141
.sortedBy { it.textOffset }
4242
.zipWithNext()
4343
.filter { (first, second) ->
44-
first.commandName() in (commandToForbiddenPredecessors[second.commandName()] ?: error("Unexpected command"))
44+
first.commandName() in (commandToForbiddenPredecessors[second.commandName()] ?: error("Unexpected command ${second.commandName()} after ${first.commandName()}"))
4545
}
4646
.map {
4747
manager.createProblemDescriptor(
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
package nl.hannahsten.texifyidea.util
2+
3+
import nl.hannahsten.texifyidea.LatexErrorReportSubmitter
4+
import org.junit.Assert.assertEquals
5+
import org.junit.Test
6+
7+
class LatexErrorReportSubmitterTest {
8+
9+
@Test
10+
fun testLongStacktrace() {
11+
val stacktrace = """
12+
com.intellij.diagnostic.PluginException: Cannot create extension (class=nl.hannahsten.texifyidea.index.file.LatexExternalEnvironmentIndex) [Plugin: nl.rubensten.texifyidea]
13+
at com.intellij.serviceContainer.ComponentManagerImpl.createError(ComponentManagerImpl.kt:980)
14+
at com.intellij.openapi.extensions.impl.XmlExtensionAdapter.doCreateInstance(XmlExtensionAdapter.kt:73)
15+
at com.intellij.openapi.extensions.impl.XmlExtensionAdapter.createInstance(XmlExtensionAdapter.kt:33)
16+
at com.intellij.openapi.extensions.impl.ExtensionPointImpl.processAdapter(ExtensionPointImpl.kt:403)
17+
at com.intellij.openapi.extensions.impl.ExtensionPointImpl.createExtensionInstances(ExtensionPointImpl.kt:376)
18+
at com.intellij.openapi.extensions.impl.ExtensionPointImpl.getExtensionList(ExtensionPointImpl.kt:222)
19+
at com.intellij.openapi.extensions.ExtensionPointName.getExtensionList(ExtensionPointName.kt:54)
20+
at com.intellij.indexing.shared.platform.api.IdeSharedIndexesState.<init>(IdeSharedIndexesState.java:38)
21+
at nl.hannahsten.texifyidea.settings.codestyle.LatexCodeStyleSettingsProvider.createCustomSettings(LatexCodeStyleSettingsProvider.kt:21)
22+
at nl.hannahsten.texifyidea.settings.codestyle.LatexCodeStyleSettingsProvider.createCustomSettings(LatexCodeStyleSettingsProvider.kt:19)
23+
at com.intellij.psi.codeStyle.CustomCodeStyleSettingsManager.addCustomSettings(CustomCodeStyleSettingsManager.java:32)
24+
at com.intellij.indexing.shared.platform.api.SharedIndexInfrastructureVersion.getIdeVersion(SharedIndexInfrastructureVersion.java:68)
25+
at com.intellij.indexing.shared.platform.impl.SharedIndexStorageUtil.openFileBasedIndexChunks(SharedIndexStorageUtil.java:54)
26+
at nl.hannahsten.texifyidea.settings.codestyle.LatexCodeStyleSettingsProvider.createCustomSettings(LatexCodeStyleSettingsProvider.kt:21)
27+
at com.intellij.indexing.shared.platform.impl.SharedIndexChunkConfigurationImpl.openFileBasedIndexChunk(SharedIndexChunkConfigurationImpl.java:657)
28+
at com.intellij.indexing.shared.platform.impl.SharedIndexChunkConfigurationImpl.registerChunk(SharedIndexChunkConfigurationImpl.java:618)
29+
at com.intellij.indexing.shared.platform.impl.SharedIndexChunkConfigurationImpl.openChunkForProject(SharedIndexChunkConfigurationImpl.java:484)
30+
Caused by: java.util.concurrent.ExecutionException: java.lang.InterruptedException
31+
at java.base/java.util.concurrent.CompletableFuture.reportGet(CompletableFuture.java:396)
32+
at java.base/java.util.concurrent.CompletableFuture.get(CompletableFuture.java:2096)
33+
at org.jetbrains.concurrency.AsyncPromise.get(AsyncPromise.kt:51)
34+
at org.jetbrains.concurrency.AsyncPromise.blockingGet(AsyncPromise.kt:130)
35+
at nl.hannahsten.texifyidea.settings.codestyle.LatexCodeStyleSettingsProvider.createCustomSettings(LatexCodeStyleSettingsProvider.kt:21)
36+
at nl.hannahsten.texifyidea.settings.codestyle.LatexCodeStyleSettingsProvider.createCustomSettings(LatexCodeStyleSettingsProvider.kt:19)
37+
""".trimIndent()
38+
val trimmedStacktrace = LatexErrorReportSubmitter.Util.filterInterestingLines(stacktrace)
39+
val expected = """
40+
com.intellij.diagnostic.PluginException: Cannot create extension (class=nl.hannahsten.texifyidea.index.file.LatexExternalEnvironmentIndex) [Plugin: nl.rubensten.texifyidea]
41+
at com.intellij.serviceContainer.ComponentManagerImpl.createError(ComponentManagerImpl.kt:980)
42+
at com.intellij.openapi.extensions.impl.XmlExtensionAdapter.doCreateInstance(XmlExtensionAdapter.kt:73)
43+
at com.intellij.openapi.extensions.impl.XmlExtensionAdapter.createInstance(XmlExtensionAdapter.kt:33)
44+
at com.intellij.openapi.extensions.impl.ExtensionPointImpl.processAdapter(ExtensionPointImpl.kt:403)
45+
at com.intellij.openapi.extensions.impl.ExtensionPointImpl.createExtensionInstances(ExtensionPointImpl.kt:376)
46+
at com.intellij.openapi.extensions.impl.ExtensionPointImpl.getExtensionList(ExtensionPointImpl.kt:222)
47+
at com.intellij.openapi.extensions.ExtensionPointName.getExtensionList(ExtensionPointName.kt:54)
48+
at com.intellij.indexing.shared.platform.api.IdeSharedIndexesState.<init>(IdeSharedIndexesState.java:38)
49+
at nl.hannahsten.texifyidea.settings.codestyle.LatexCodeStyleSettingsProvider.createCustomSettings(LatexCodeStyleSettingsProvider.kt:21)
50+
at nl.hannahsten.texifyidea.settings.codestyle.LatexCodeStyleSettingsProvider.createCustomSettings(LatexCodeStyleSettingsProvider.kt:19)
51+
at com.intellij.psi.codeStyle.CustomCodeStyleSettingsManager.addCustomSettings(CustomCodeStyleSettingsManager.java:32)
52+
(...)
53+
at com.intellij.indexing.shared.platform.impl.SharedIndexStorageUtil.openFileBasedIndexChunks(SharedIndexStorageUtil.java:54)
54+
at nl.hannahsten.texifyidea.settings.codestyle.LatexCodeStyleSettingsProvider.createCustomSettings(LatexCodeStyleSettingsProvider.kt:21)
55+
at com.intellij.indexing.shared.platform.impl.SharedIndexChunkConfigurationImpl.openFileBasedIndexChunk(SharedIndexChunkConfigurationImpl.java:657)
56+
(...)
57+
at com.intellij.indexing.shared.platform.impl.SharedIndexChunkConfigurationImpl.openChunkForProject(SharedIndexChunkConfigurationImpl.java:484)
58+
Caused by: java.util.concurrent.ExecutionException: java.lang.InterruptedException
59+
at java.base/java.util.concurrent.CompletableFuture.reportGet(CompletableFuture.java:396)
60+
(...)
61+
at org.jetbrains.concurrency.AsyncPromise.blockingGet(AsyncPromise.kt:130)
62+
at nl.hannahsten.texifyidea.settings.codestyle.LatexCodeStyleSettingsProvider.createCustomSettings(LatexCodeStyleSettingsProvider.kt:21)
63+
at nl.hannahsten.texifyidea.settings.codestyle.LatexCodeStyleSettingsProvider.createCustomSettings(LatexCodeStyleSettingsProvider.kt:19)
64+
""".trimIndent()
65+
assertEquals(expected, trimmedStacktrace)
66+
}
67+
}

0 commit comments

Comments
 (0)