Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Shorten long stacktraces before submitting #3740

Merged
merged 3 commits into from
Nov 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
### Added

### Fixed
* Improve error report submitter for long stacktraces

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

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

### Fixed

* Fix exception #3557 if using bibtex structure view when bibtex file type is reassignd to plain text
* Avoid referencing obsolete psifiles, fix exception #3635

Expand Down
24 changes: 22 additions & 2 deletions src/nl/hannahsten/texifyidea/LatexErrorReportSubmitter.kt
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,18 @@ class LatexErrorReportSubmitter : ErrorReportSubmitter() {
?: event?.message
?: "Crash Report: <Fill in title>"
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})" }
Expand All @@ -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(
Expand Down Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
@@ -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.<init>(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.<init>(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)
}
}
Loading