Skip to content

Commit

Permalink
Better fallback for invalid syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
Dueris committed May 27, 2024
1 parent 9153dd7 commit 7ebb0fe
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
10 changes: 8 additions & 2 deletions calio/src/main/java/me/dueris/calio/CraftCalio.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public void start(boolean debug) {
this.isDebugging = debug;
debug("Starting CraftCalio parser...");
this.keys.stream().sorted(Comparator.comparingInt(AccessorKey::getPriority)).forEach(accessorKey -> datapackDirectoriesToParse.forEach(root -> {
for (File datapack : root.listFiles()) {
packLoop: for (File datapack : root.listFiles()) {
try {
FileReader fileReader = FileReaderFactory.createFileReader(datapack.toPath());
if (fileReader == null) continue;
Expand All @@ -83,7 +83,13 @@ public void start(boolean debug) {
line.append(newLine);
}
String finishedLine = line.toString().replace("\n", "");
JsonObject powerParser = JsonParser.parseReader(new StringReader(finishedLine)).getAsJsonObject();
JsonObject powerParser;
try {
powerParser = JsonParser.parseReader(new StringReader(finishedLine)).getAsJsonObject();
} catch (Throwable throwable) {
getLogger().severe("An unhandled exception occurred when parsing a json file! Invalid syntax? The datapack will not be loaded.");
continue packLoop;
}
NamespacedKey namespacedKey = new NamespacedKey(namespace, key);
JsonObject remappedJsonObject = JsonObjectRemapper.remapJsonObject(powerParser, namespacedKey);
newLoadingPrioritySortedMap.put(new Pair<>(remappedJsonObject, namespacedKey), remappedJsonObject.has("loading_priority") ? remappedJsonObject.getAsJsonPrimitive("loading_priority").getAsInt() : 0);
Expand Down
12 changes: 7 additions & 5 deletions calio/src/main/java/me/dueris/calio/parse/CalioJsonParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,14 @@ public static FactoryHolder initilize(Pair<JsonObject, NamespacedKey> pair, Acce
Constructor<? extends FactoryHolder> constructor = findConstructor(data, holder);
if (constructor != null) {
FactoryHolder created = ConstructorCreator.invoke(constructor, data, pair);
created.ofResourceLocation(pair.getSecond());
if (created.canRegister()) {
CalioRegistry.INSTANCE.retrieve(accessorKey.getRegistryKey()).registerOrThrow(created);
created.bootstrap();
if (created != null) {
created.ofResourceLocation(pair.getSecond());
if (created.canRegister()) {
CalioRegistry.INSTANCE.retrieve(accessorKey.getRegistryKey()).registerOrThrow(created);
created.bootstrap();
}
return created;
}
return created;
} else throw new IllegalStateException("Unable to find constructor for provided type!");
} catch (Throwable throwable) {
throwable.printStackTrace();
Expand Down

0 comments on commit 7ebb0fe

Please sign in to comment.