Skip hotloads while a touched pack JSON does not parse

A bad save still hotloaded: the loaders return null for unparseable files, so the pack lost those biomes or regions. The new PackHotloadGuard keeps files that fail to parse until they parse, skips the hotload, logs it and sends a failed studio hotload message. Both the Bukkit generator and the modded studio hotload service gate on it, and the callback returns normally so the watcher does not retry.

v3: fe825040a
This commit is contained in:
piexel committed 2026-11-10 10:43:34 +01:00
1 parent 5efffcd0b2
commit 0b5aa54df7
6 files changed
+304 -3

No files matched your search

@@ -0,0 +1,61 @@
package art.arcane.iris.core.project;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.util.List;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
public class PackHotloadGuardTest {
@Rule
public TemporaryFolder temporaryFolder = new TemporaryFolder();
private File write(String relativePath, String content) throws IOException {
File file = new File(temporaryFolder.getRoot(), relativePath);
Files.createDirectories(file.getParentFile().toPath());
Files.writeString(file.toPath(), content);
return file;
}
@Test
public void allowsAHotloadWhenEveryTouchedFileParses() throws IOException {
PackHotloadGuard guard = new PackHotloadGuard(temporaryFolder.getRoot());
assertTrue(guard.allowsHotload(List.of(write("biomes/plains.json", "{}"))));
}
@Test
public void skipsAHotloadWhileATouchedFileIsBroken() throws IOException {
PackHotloadGuard guard = new PackHotloadGuard(temporaryFolder.getRoot());
assertFalse(guard.allowsHotload(List.of(write("biomes/plains.json", "{"))));
}
@Test
public void keepsSkippingOtherSavesUntilTheBrokenFileIsFixed() throws IOException {
PackHotloadGuard guard = new PackHotloadGuard(temporaryFolder.getRoot());
write("biomes/plains.json", "{");
guard.allowsHotload(List.of(new File(temporaryFolder.getRoot(), "biomes/plains.json")));
File region = write("regions/hills.json", "{}");
assertFalse(guard.allowsHotload(List.of(region)));
write("biomes/plains.json", "{}");
assertTrue(guard.allowsHotload(List.of(region)));
}
@Test
public void touchedFilesAreTheCreatedOnesFollowedByTheChangedOnes() {
File created = new File("created.json");
File changed = new File("changed.json");
assertEquals(List.of(created, changed), PackHotloadGuard.touched(List.of(created), List.of(changed)));
}
}
@@ -0,0 +1,114 @@
package art.arcane.iris.core.project;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.util.List;
import java.util.Map;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
public class UnreadablePackFilesTest {
@Rule
public TemporaryFolder temporaryFolder = new TemporaryFolder();
private final UnreadablePackFiles files = new UnreadablePackFiles();
private File write(String name, String content) throws IOException {
File file = new File(temporaryFolder.getRoot(), name);
Files.writeString(file.toPath(), content);
return file;
}
@Test
public void acceptsTrailingCommasLikeTheLoaders() throws IOException {
File biome = write("biome.json", """
{
"name": "Plains",
"children": ["a", "b",],
}
""");
assertTrue(files.recheck(List.of(biome)).isEmpty());
}
@Test
public void reportsCommentsBecauseTheLoadersCannotReadThem() throws IOException {
File biome = write("biome.json", """
{
// the loaders reject this
"name": "Plains"
}
""");
assertEquals(1, files.recheck(List.of(biome)).size());
}
@Test
public void acceptsListsAtTheTopOfAFile() throws IOException {
assertTrue(files.recheck(List.of(write("list.json", "[1, 2]"))).isEmpty());
}
@Test
public void reportsWhereASyntaxErrorIs() throws IOException {
File biome = write("biome.json", """
{
"name": "Plains",
"children": [
"a"
"b"
]
}
""");
Map<File, String> unreadable = files.recheck(List.of(biome));
assertTrue(unreadable.get(biome), unreadable.get(biome).contains("line"));
}
@Test
public void reportsAnEmptyFile() throws IOException {
File biome = write("biome.json", "");
assertEquals(1, files.recheck(List.of(biome)).size());
}
@Test
public void reportsAFileThatIsNotAnObject() throws IOException {
File biome = write("biome.json", "42");
assertEquals(1, files.recheck(List.of(biome)).size());
}
@Test
public void keepsHoldingAFileUntilItParses() throws IOException {
File broken = write("broken.json", "{");
File other = write("other.json", "{}");
files.recheck(List.of(broken));
assertEquals(1, files.recheck(List.of(other)).size());
write("broken.json", "{}");
assertTrue(files.recheck(List.of(other)).isEmpty());
}
@Test
public void forgetsADeletedFile() throws IOException {
File broken = write("broken.json", "{");
files.recheck(List.of(broken));
Files.delete(broken.toPath());
assertTrue(files.recheck(List.of()).isEmpty());
}
@Test
public void skipsObjectFiles() throws IOException {
assertTrue(files.recheck(List.of(write("tree.iob", "not json"))).isEmpty());
}
}