Handle fabric.mod.json file being empty (#1280)

* Throw a nicer error when the fabric.mod.json file is empty

* Don't fail just log.
This commit is contained in:
modmuss
2025-04-07 11:54:08 +01:00
committed by GitHub
parent 186b774a2e
commit 2af4b7e591

View File

@@ -116,7 +116,15 @@ public final class FabricModJsonFactory {
}
try (Reader reader = Files.newBufferedReader(file.toPath(), StandardCharsets.UTF_8)) {
return create(LoomGradlePlugin.GSON.fromJson(reader, JsonObject.class), new FabricModJsonSource.SourceSetSource(project, sourceSets));
final JsonObject modJson = LoomGradlePlugin.GSON.fromJson(reader, JsonObject.class);
if (modJson == null) {
// fromJson returns null if the file is empty
LOGGER.warn("Failed to parse empty fabric.mod.json: {}", file.getAbsolutePath());
return null;
}
return create(modJson, new FabricModJsonSource.SourceSetSource(project, sourceSets));
} catch (JsonSyntaxException e) {
LOGGER.warn("Failed to parse fabric.mod.json: {}", file.getAbsolutePath());
return null;