mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2026-11-28 16:54:04 +00:00
A module resource that fails to read throws with the reason
ModuleResourceFiles.read reports the file as before and then throws an IllegalStateException carrying the decoder's message, so validators can say what is wrong instead of pointing at the log.
This commit is contained in:
1 parent
302166f115
commit
37851fee0c
3 files changed
+34
-6
No files matched your search
@@ -31,6 +31,8 @@ import art.arcane.iris.builtin.spawn.SpawnGroup;
|
||||
import art.arcane.iris.builtin.spawn.SpawnWeather;
|
||||
import art.arcane.iris.builtin.spawn.Spawner;
|
||||
import art.arcane.iris.builtin.spawn.SpawnerSettings;
|
||||
import art.arcane.iris.core.loader.IrisData;
|
||||
import art.arcane.iris.engine.loot.LootResources;
|
||||
import art.arcane.volmlib.util.json.JSONObject;
|
||||
import com.google.gson.Gson;
|
||||
import com.volmit.FeatureAttachment.Target;
|
||||
@@ -56,6 +58,9 @@ import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertSame;
|
||||
import static org.junit.Assert.assertThrows;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.mockito.Mockito.RETURNS_DEEP_STUBS;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
/**
|
||||
* Files of the overworld pack exactly as they were before the loot and spawn fields became module settings (copied from
|
||||
@@ -270,6 +275,21 @@ public class LootAndSpawnPackDecodingTest {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void aLootTableOfTheWrongShapeFailsToReadSayingWhy() throws IOException {
|
||||
Path brokenPack = folder.newFolder("broken-pack").toPath();
|
||||
Files.createDirectories(brokenPack.resolve("loot"));
|
||||
Files.writeString(brokenPack.resolve("loot/broken.json"), "{\"rarity\": [1], \"loot\": [{\"type\": \"stone\"}]}");
|
||||
IrisData data = mock(IrisData.class, RETURNS_DEEP_STUBS);
|
||||
when(data.getDataFolder()).thenReturn(brokenPack.toFile());
|
||||
when(data.getModules().settings()).thenReturn(decoder);
|
||||
|
||||
IllegalStateException failure = assertThrows(IllegalStateException.class,
|
||||
() -> new ModuleResourceFiles<>(data, LootResources.TABLES).read("broken"));
|
||||
|
||||
assertTrue(failure.getMessage(), failure.getMessage().contains("$.rarity"));
|
||||
}
|
||||
|
||||
private JSONObject file(String relative) throws IOException {
|
||||
return new JSONObject(Files.readString(packFolder.resolve(relative)));
|
||||
}
|
||||
|
||||
@@ -155,9 +155,9 @@ public class LootValidatorTest {
|
||||
public void aTableThatFailsToLoadIsReportedWithoutStoppingTheCheck() {
|
||||
table("fine", "{\"loot\":[{\"type\":\"stone\"}]}");
|
||||
table("broken", "{\"loot\":[{\"type\":\"stone\"}]}");
|
||||
when(resources.find(LootResources.TABLES.key(new ResourceId("test", "broken")))).thenThrow(new IllegalStateException("unreadable"));
|
||||
when(resources.find(LootResources.TABLES.key(new ResourceId("test", "broken")))).thenThrow(new IllegalStateException("Expected an int but was STRING at line 1 column 12 path $.rarity"));
|
||||
|
||||
assertEquals(List.of("Loot table 'broken' cannot be read; the log says what is wrong with the file."), errors());
|
||||
assertEquals(List.of("Loot table 'broken' cannot be read: Expected an int but was STRING at line 1 column 12 path $.rarity"), errors());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
Reference in new issue
Block a user