Return a dummy when recipe deserialization fails. Closes #2563. (#2565). Thanks to Technici4n

This commit is contained in:
Technici4n 2021-10-08 00:00:22 +02:00 committed by GitHub
parent 2d9cdfbdc9
commit 0ddf6688c9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -49,21 +49,24 @@ public record RebornRecipeType<R extends RebornRecipe>(
throw new RuntimeException("RebornRecipe type not supported!");
}
R recipe = newRecipe(recipeId);
try {
R recipe = newRecipe(recipeId);
if (!ConditionManager.shouldLoadRecipe(json)) {
recipe.makeDummy();
return recipe;
}
recipe.deserialize(json);
return recipe;
} catch (Throwable t) {
t.printStackTrace();
RebornCore.LOGGER.error("Failed to read recipe: " + recipeId);
RebornCore.LOGGER.error("Failed to read recipe: " + recipeId, t);
// Make a new recipe - don't reuse the existing recipe object because it might be in an invalid state if an
// exception was thrown in the middle of its deserialization.
R recipe = newRecipe(recipeId);
recipe.makeDummy();
return recipe;
}
return recipe;
}
public JsonObject toJson(R recipe) {