-
Notifications
You must be signed in to change notification settings - Fork 6
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
Update description with crash #627
base: master
Are you sure you want to change the base?
Changes from all commits
41eee62
65ac2d3
3300974
a60cba2
1b5d3b7
66dbce4
6387c2a
a92c10f
331bd64
082b8a4
c7dc318
fbc34be
ce84853
69d379d
50a46d4
54cede8
a6e1b0b
f1c3be8
d158019
0409c1b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,92 @@ | ||||||||||
package io.github.mojira.arisa.modules | ||||||||||
|
||||||||||
import arrow.core.Either | ||||||||||
import arrow.core.extensions.fx | ||||||||||
import arrow.core.left | ||||||||||
import arrow.core.right | ||||||||||
import arrow.syntax.function.partially2 | ||||||||||
import io.github.mojira.arisa.domain.Issue | ||||||||||
import io.github.mojira.arisa.infrastructure.AttachmentUtils | ||||||||||
import com.urielsalis.mccrashlib.Crash | ||||||||||
import com.urielsalis.mccrashlib.CrashReader | ||||||||||
import com.urielsalis.mccrashlib.deobfuscator.getSafeChildPath | ||||||||||
import java.nio.file.Files | ||||||||||
import java.time.Instant | ||||||||||
|
||||||||||
class CrashInfoModule( | ||||||||||
private val crashReportExtensions: List<String>, | ||||||||||
private val crashReader: CrashReader | ||||||||||
) : Module { | ||||||||||
override fun invoke(issue: Issue, lastRun: Instant): Either<ModuleError, ModuleResponse> = with(issue) { | ||||||||||
Either.fx { | ||||||||||
val crashes = AttachmentUtils(crashReportExtensions, crashReader).extractCrashesFromAttachments(issue) | ||||||||||
val newCrashes = assertContainsNewCrash(crashes, lastRun).bind() | ||||||||||
uploadDeobfuscatedCrashes(issue, newCrashes) | ||||||||||
|
||||||||||
newCrashes | ||||||||||
.filter { it.second is Crash.Minecraft } | ||||||||||
.filterNot { it.first.name.endsWith("deobfuscated.txt") } | ||||||||||
Comment on lines
+26
to
+28
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should probably restrict this to crash reports attached by the reporter (or by a helper / moderator?). |
||||||||||
.forEach { | ||||||||||
if (!description!!.contains("""\{code.*${it.first.name}]}(\S|\s)*\{code}""".toRegex())) { | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is Additionally we should probably only add the crash report to the description if it does not contain any (instead of checking for the specific crash report name), to prevent adding multiple crash report snippets. Therefore we should probably only consider The regex could probably changed to this:
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe this regex is too unspecific though and causes some false negatives, e.g. when |
||||||||||
updateDescription( | ||||||||||
description + "\n\n" + | ||||||||||
generateCrashMessage(it.first.name, it.second as Crash.Minecraft) | ||||||||||
) | ||||||||||
} | ||||||||||
} | ||||||||||
} | ||||||||||
} | ||||||||||
|
||||||||||
private fun generateCrashMessage(name: String, minecraft: Crash.Minecraft) = | ||||||||||
"{code:title=(${minecraft.minecraftVersion}) [^$name]}\n\n" + | ||||||||||
"Description: ${minecraft.exception.split("\n").first()}\n\n" + | ||||||||||
"Exception: ${minecraft.exception}\n\n" + | ||||||||||
(if (minecraft.deobfException != null) "Deobfuscated: ${minecraft.deobfException}\n" else "\n") + | ||||||||||
"{code}\n" | ||||||||||
|
||||||||||
private fun uploadDeobfuscatedCrashes(issue: Issue, crashes: List<Pair<AttachmentUtils.TextDocument, Crash>>) { | ||||||||||
val minecraftCrashesWithDeobf = crashes | ||||||||||
.map { it.first.name to it.second } | ||||||||||
.filter { it.second is Crash.Minecraft } | ||||||||||
.map { it.first to (it.second as Crash.Minecraft).deobf } | ||||||||||
.filter { it.second != null } | ||||||||||
.filterNot { | ||||||||||
issue.attachments.any { attachment -> | ||||||||||
attachment.name == getDeobfName(it.first) || attachment.name.endsWith( | ||||||||||
"deobfuscated.txt" | ||||||||||
) | ||||||||||
} | ||||||||||
} | ||||||||||
minecraftCrashesWithDeobf.forEach { | ||||||||||
val tempDir = Files.createTempDirectory("arisa-crash-upload").toFile() | ||||||||||
val safePath = getSafeChildPath(tempDir, getDeobfName(it.first)) | ||||||||||
if (safePath == null) { | ||||||||||
tempDir.delete() | ||||||||||
} else { | ||||||||||
safePath.writeText(it.second!!) | ||||||||||
issue.addAttachment(safePath) { | ||||||||||
// Once uploaded, delete the temp directory containing the crash report | ||||||||||
tempDir.deleteRecursively() | ||||||||||
} | ||||||||||
} | ||||||||||
} | ||||||||||
} | ||||||||||
|
||||||||||
private fun getDeobfName(name: String): String = | ||||||||||
"${name.substringBeforeLast(".").replace("\\", "").replace("/", "")}-deobfuscated.txt" | ||||||||||
|
||||||||||
private fun crashNewlyAdded(crash: Pair<AttachmentUtils.TextDocument, Crash>, lastRun: Instant) = | ||||||||||
crash.first.created.isAfter(lastRun) | ||||||||||
|
||||||||||
private fun assertContainsNewCrash( | ||||||||||
crashes: List<Pair<AttachmentUtils.TextDocument, Crash>>, | ||||||||||
lastRun: Instant | ||||||||||
): Either<OperationNotNeededModuleResponse, List<Pair<AttachmentUtils.TextDocument, Crash>>> { | ||||||||||
val newCrashes = crashes.filter(::crashNewlyAdded.partially2(lastRun)) | ||||||||||
return if (newCrashes.isNotEmpty()) { | ||||||||||
newCrashes.right() | ||||||||||
} else { | ||||||||||
OperationNotNeededModuleResponse.left() | ||||||||||
} | ||||||||||
} | ||||||||||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not needed anymore, is it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It'd be nice to leave it for future purposes.