Skip to content

Commit 7fe8bb7

Browse files
committed
Hotfix .mcmeta parse causing CTD because of exception hierarchy
* Fixes #71 * JsonParseException not being IOException
1 parent 3761df3 commit 7fe8bb7

File tree

2 files changed

+23
-2
lines changed

2 files changed

+23
-2
lines changed

src/main/java/com/ldtteam/blockui/util/SafeError.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import com.ldtteam.blockui.mod.Log;
44
import net.minecraftforge.fml.loading.FMLEnvironment;
5+
import org.slf4j.Logger;
56

67
/**
78
* Utility class for throwing errors which is safe during production.
@@ -24,4 +25,22 @@ public static void throwInDev(final RuntimeException exception)
2425
throw exception;
2526
}
2627
}
28+
29+
/**
30+
* Safe error throw call that only throws an exception during development, but logs an error in production instead so no crashes to desktop may occur.
31+
*
32+
* @param exception the exception instance.
33+
* @param logger calling class logger
34+
*/
35+
public static void throwInDev(final RuntimeException exception, final Logger logger)
36+
{
37+
if (FMLEnvironment.production)
38+
{
39+
logger.error(exception.getMessage(), exception);
40+
}
41+
else
42+
{
43+
throw exception;
44+
}
45+
}
2746
}

src/main/java/com/ldtteam/blockui/util/texture/SpriteTexture.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package com.ldtteam.blockui.util.texture;
22

3+
import com.google.gson.JsonParseException;
4+
import com.ldtteam.blockui.util.SafeError;
35
import com.ldtteam.blockui.util.resloc.OutOfJarResourceLocation;
46
import com.mojang.blaze3d.platform.TextureUtil;
57
import net.minecraft.client.renderer.texture.AbstractTexture;
@@ -112,9 +114,9 @@ public static SpriteTexture checkLoaded(final ResourceLocation resourceLocation,
112114
{
113115
metadata = OutOfJarResourceLocation.getResourceHandle(resourceLocation, resourceManager).metadata();
114116
}
115-
catch (final IOException e)
117+
catch (final IOException | JsonParseException e)
116118
{
117-
LOGGER.error("Parsing sprite metadata", e);
119+
SafeError.throwInDev(new RuntimeException("Parsing sprite metadata failed for: " + resourceLocation, e), LOGGER);
118120
return null;
119121
}
120122

0 commit comments

Comments
 (0)