Skip to content

Commit

Permalink
Store information about modded world separately (#21)
Browse files Browse the repository at this point in the history
It was discussed internally that it might not always be desired to consider
a crash report of a vanilla client or server for a modded world as modded.
Potentially the mod had no effect on the world and the crash occurs in
vanilla worlds as well.
  • Loading branch information
Marcono1234 authored Nov 23, 2021
1 parent 3989aad commit a00d4c7
Show file tree
Hide file tree
Showing 9 changed files with 30 additions and 9 deletions.
8 changes: 8 additions & 0 deletions src/main/kotlin/com/urielsalis/mccrashlib/Crash.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,14 @@ sealed class Crash {

data class Minecraft(
val modded: Boolean,
/**
* Whether the level had been opened with a modded client or server in the past. This does
* not necessarily mean that the mod had any effect on the level, or that the client or
* server is still modded (see [modded]).
*
* `null` if unknown, or if no level information exists in the crash report.
*/
val wasLevelOpenedModded: Boolean?,
val exception: String,
/** Minecraft version ID; `null` if unknown */
val minecraftVersion: String?,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ import java.io.File

/*
Minecraft crashes are separated into sections starting and ending with --
"Minecraft crash report" contains the exception, "System Details" contains more information
The exception starts with java.lang and its all lines until the first empty line
System details contains a : separated key value pair. We care about Is Modded
"Minecraft Crash Report" contains the exception, "System Details" contains more information
The exception starts with java.lang and it includes all lines until the first empty line
"System Details" contains a : separated key value pair. We care about "Is Modded"
*/
private const val crashReportSection = "Minecraft Crash Report"
private const val systemDetailsSection = "System Details"
Expand All @@ -32,8 +32,9 @@ class MinecraftCrashParser : CrashParser {
return Either.left(SectionsNotFound)
}
val details = getDetails(sections[systemDetailsSection] ?: error("System details section not found"))
val isModded = isGameModded(details)
val affectedLevel = sections[affectedLevelSection]?.let(::getDetails)
val isModded = isGameModded(details) || affectedLevel?.let(::wasLevelModded) == true
val wasLevelModded = affectedLevel?.let(::wasLevelModded)
val exception = getException(sections[crashReportSection] ?: error("Crash report section not found"))
val version = getMinecraftVersion(details)
val type = getType(details)
Expand All @@ -51,6 +52,7 @@ class MinecraftCrashParser : CrashParser {
Either.right(
Crash.Minecraft(
isModded,
wasLevelModded,
it,
version,
isClient,
Expand All @@ -73,8 +75,12 @@ class MinecraftCrashParser : CrashParser {
!contains("Probably Not", true) && !contains("Unknown", true)
}

private fun wasLevelModded(affectedLevelDetails: Map<String, String>) =
affectedLevelDetails[levelWasModded] == "true"
private fun wasLevelModded(affectedLevelDetails: Map<String, String>): Boolean? =
when (affectedLevelDetails[levelWasModded]) {
"true" -> true
"false" -> false
else -> null
}

private fun getException(lines: List<String>): Option<String> {
var foundStart = false
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"modded" : false,
"wasLevelOpenedModded" : null,
"exception" : "java.util.concurrent.CompletionException: java.lang.OutOfMemoryError: Java heap space\nat atd.c(SourceFile:151)\n...",
"minecraftVersion" : "21w42a",
"isClient" : true,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"modded" : false,
"wasLevelOpenedModded" : null,
"exception" : "java.lang.Throwable\nat cvi.b(SourceFile:530)\nat cvk.m(SourceFile:1477)\nat cvk.e(SourceFile:925)\nat cvk.b(SourceFile:411)\nat net.minecraft.client.main.Main.main(SourceFile:154)",
"minecraftVersion" : "1.14.2",
"isClient" : true,
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"modded" : false,
"wasLevelOpenedModded" : null,
"exception" : "java.lang.IllegalArgumentException: bound must be positive\nat java.util.Random.nextInt(Random.java:388)\nat ary.a(SourceFile:194)\nat ary.a(SourceFile:49)\nat arm.a(SourceFile:389)\nat asu.a(SourceFile:86)\nat bgv.a(SourceFile:472)\nat qs.a(SourceFile:174)\nat bfh.a(SourceFile:861)\nat qs.c(SourceFile:104)\nat qs.d(SourceFile:116)\nat aqu.a(SourceFile:276)\nat aqu.f(SourceFile:272)\nat aqu.p(SourceFile:657)\nat awn.b(SourceFile:66)\nat atr.a(SourceFile:437)\nat qt.h(SourceFile:384)\nat qt.c(SourceFile:202)\nat net.minecraft.server.MinecraftServer.z(SourceFile:599)\nat po.z(SourceFile:305)\nat net.minecraft.server.MinecraftServer.y(SourceFile:531)\nat net.minecraft.server.MinecraftServer.run(SourceFile:447)\nat java.lang.Thread.run(Thread.java:748)",
"minecraftVersion" : "1.8",
"isClient" : false,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"modded" : false,
"wasLevelOpenedModded" : null,
"exception" : "org.lwjgl.LWJGLException: Pixel format not accelerated",
"minecraftVersion" : "1.8.9",
"isClient" : true,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"modded" : true,
"wasLevelOpenedModded" : null,
"exception" : "java.lang.Throwable\nat cep.b(SourceFile:486)\nat ces.ae_(SourceFile:1311)\nat ces.c(SourceFile:808)\nat ces.a(SourceFile:380)\nat net.minecraft.client.main.Main.main(SourceFile:144)",
"minecraftVersion" : "1.13-pre6",
"isClient" : true,
Expand Down
1 change: 1 addition & 0 deletions src/test/resources/crashes/minecraft/watchdog-parsed.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"modded" : false,
"wasLevelOpenedModded" : null,
"exception" : "java.lang.Error\nat java.io.RandomAccessFile.read0(Native Method)\nat java.io.RandomAccessFile.read(RandomAccessFile.java:337)\nat java.io.RandomAccessFile.readInt(RandomAccessFile.java:799)\nat byi.<init>(SourceFile:128)\nat byj.a(SourceFile:40)\nat byj.e(SourceFile:47)\nat uw.g(SourceFile:816)\nat uw.j(SourceFile:506)\nat uw$$Lambda$2128/201498946.get(Unknown Source)\nat java.util.concurrent.CompletableFuture$AsyncSupply.run(CompletableFuture.java:1590)\nat agq.h(SourceFile:144)\nat agq.q(SourceFile:118)\nat vi$a.q(SourceFile:550)\nat agq.c(SourceFile:127)\nat vi.a(SourceFile:135)\nat bhr.a(SourceFile:194)\nat bhu.a(SourceFile:106)\nat ceu.a(SourceFile:128)\nat bxi.a(SourceFile:112)\nat vk.a(SourceFile:1176)\nat sq.a(SourceFile:47)\nat sq.a(SourceFile:41)\nat sq$$Lambda$1631/527979439.run(Unknown Source)\nat com.mojang.brigadier.CommandDispatcher.execute(CommandDispatcher.java:262)\nat com.mojang.brigadier.CommandDispatcher.execute(CommandDispatcher.java:176)\nat ce.a(SourceFile:225)\nat wc.c(SourceFile:1067)\nat wc.a(SourceFile:1054)\nat ny.a(SourceFile:37)\nat ny.a(SourceFile:9)\nat ke.a(SourceFile:21)\nat ke$$Lambda$2445/1038006101.run(Unknown Source)\nat rk.run(SourceFile:18)\nat agq.h(SourceFile:144)\nat agu.h(SourceFile:23)\nat agq.q(SourceFile:118)\nat net.minecraft.server.MinecraftServer.aX(SourceFile:712)\nat net.minecraft.server.MinecraftServer.q(SourceFile:706)\nat agq.c(SourceFile:127)\nat net.minecraft.server.MinecraftServer.p(SourceFile:691)\nat net.minecraft.server.MinecraftServer.run(SourceFile:646)\nat java.lang.Thread.run(Thread.java:748)",
"minecraftVersion" : "1.14.4-pre6",
"isClient" : false,
Expand Down

0 comments on commit a00d4c7

Please sign in to comment.