Leave custom data untouched when a versioned transformer fails

This commit is contained in:
Ruling-0 committed 2026-11-25 14:45:59 -06:00
1 parent c7f139c53a
commit 93c77c7e5f
6 files changed
+125 -53

No files matched your search

@@ -1,6 +1,7 @@
package com.gtnewhorizons.postea.api;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;
import java.util.Arrays;
import java.util.Collections;
@@ -30,4 +31,22 @@ class CustomDataReplacementManagerTest {
assertEquals(5, VersionStamps.stored(stamps, "mod:absent"));
assertEquals(2, VersionStamps.stored(saved, "mod:present"));
}
@Test
void aThrowingTransformerLeavesTheRootAsRead() {
StubTransformer rewrites = new StubTransformer("mod:rewrites", 2);
rewrites.customData = ctx -> ctx.root()
.setString("data", "new");
StubTransformer fails = new StubTransformer("mod:fails", 2);
fails.customData = ctx -> { throw new IllegalStateException("broken"); };
NBTTagCompound root = new NBTTagCompound();
root.setString("data", "old");
NBTTagCompound asRead = (NBTTagCompound) root.copy();
// The ReportedException's CrashReport initializes FML, which fails outside a launched game.
assertThrows(
Throwable.class,
() -> CustomDataReplacementManager.transform("mod:storage", root, Arrays.asList(rewrites, fails)));
assertEquals(asRead, root);
}
}