simplify error messages

This commit is contained in:
gnembon committed 2021-03-09 13:29:20 -04:00
1 parent d72a617290
commit 2d1b53258c
9 files changed
+25 -21

No files matched your search

@@ -162,10 +162,11 @@ public class Auxiliary {
{ {
expression.addLazyFunction("sound", -1, (c, t, lv) -> { expression.addLazyFunction("sound", -1, (c, t, lv) -> {
CarpetContext cc = (CarpetContext)c; CarpetContext cc = (CarpetContext)c;
Identifier soundName = new Identifier(lv.get(0).evalValue(c).getString()); String rawString = lv.get(0).evalValue(c).getString();
Identifier soundName = new Identifier(rawString);
Vector3Argument locator = Vector3Argument.findIn(cc, lv, 1); Vector3Argument locator = Vector3Argument.findIn(cc, lv, 1);
if (Registry.SOUND_EVENT.get(soundName) == null) if (Registry.SOUND_EVENT.get(soundName) == null)
throw new ThrowStatement("No such sound: "+soundName.getPath(), Throwables.UNKNOWN_SOUND); throw new ThrowStatement(rawString, Throwables.UNKNOWN_SOUND);
float volume = 1.0F; float volume = 1.0F;
float pitch = 1.0F; float pitch = 1.0F;
SoundCategory mixer = SoundCategory.MASTER; SoundCategory mixer = SoundCategory.MASTER;
@@ -861,7 +862,7 @@ public class Auxiliary {
state = ((CarpetScriptHost) c.host).readFileTag(fdesc.getLeft(), fdesc.getRight()); state = ((CarpetScriptHost) c.host).readFileTag(fdesc.getLeft(), fdesc.getRight());
} catch (CrashException e) } catch (CrashException e)
{ {
throw new ThrowStatement("Couldn't read NBT data", Throwables.NBT_READ); throw new ThrowStatement((fdesc.getRight()?"shared/":"")+ fdesc.getLeft(), Throwables.NBT_READ);
} }
if (state == null) return LazyValue.NULL; if (state == null) return LazyValue.NULL;
@@ -879,7 +880,10 @@ public class Auxiliary {
Throwable exc = e; Throwable exc = e;
if(e.getCause() != null) if(e.getCause() != null)
exc = e.getCause(); exc = e.getCause();
throw new ThrowStatement("Failed to read JSON file: "+exc.getMessage(), Throwables.JSON_READ); throw new ThrowStatement(MapValue.wrap(ImmutableMap.of(
StringValue.of("error"), StringValue.of(exc.getMessage()),
StringValue.of("path"), StringValue.of((fdesc.getRight()?"shared/":"")+ fdesc.getLeft())
)), Throwables.JSON_READ);
} }
Value parsedJson = GSON.fromJson(json, Value.class); Value parsedJson = GSON.fromJson(json, Value.class);
if (parsedJson == null) if (parsedJson == null)
@@ -973,7 +977,7 @@ public class Auxiliary {
state = ((CarpetScriptHost)((CarpetContext)c).host).readFileTag(file, shared); state = ((CarpetScriptHost)((CarpetContext)c).host).readFileTag(file, shared);
} catch (CrashException e) } catch (CrashException e)
{ {
throw new ThrowStatement("Failed to read App data", Throwables.NBT_READ); throw new ThrowStatement("app data", Throwables.NBT_READ);
} }
if (state == null) if (state == null)
return (cc, tt) -> Value.NULL; return (cc, tt) -> Value.NULL;
@@ -193,7 +193,7 @@ public class Inventories {
String itemStr = lv.get(0).evalValue(c).getString(); String itemStr = lv.get(0).evalValue(c).getString();
Item item; Item item;
Identifier id = new Identifier(itemStr); Identifier id = new Identifier(itemStr);
item = Registry.ITEM.getOrEmpty(id).orElseThrow(() -> new ThrowStatement("Incorrect item: "+itemStr, Throwables.UNKNOWN_ITEM)); item = Registry.ITEM.getOrEmpty(id).orElseThrow(() -> new ThrowStatement(itemStr, Throwables.UNKNOWN_ITEM));
if (!item.hasRecipeRemainder()) return LazyValue.NULL; if (!item.hasRecipeRemainder()) return LazyValue.NULL;
Value ret = new StringValue(NBTSerializableValue.nameFromRegistryId(Registry.ITEM.getId(item.getRecipeRemainder()))); Value ret = new StringValue(NBTSerializableValue.nameFromRegistryId(Registry.ITEM.getId(item.getRecipeRemainder())));
@@ -133,7 +133,7 @@ public class Scoreboards {
criterion = ScoreboardCriterion.createStatCriterion(critetionName).orElse(null); criterion = ScoreboardCriterion.createStatCriterion(critetionName).orElse(null);
if (criterion==null) if (criterion==null)
{ {
throw new ThrowStatement("Unknown scoreboard criterion: "+critetionName, Throwables.UNKNOWN_CRITERION); throw new ThrowStatement(critetionName, Throwables.UNKNOWN_CRITERION);
} }
} }
@@ -339,7 +339,7 @@ public class WorldAccess {
if (!"any".equals(poiType)) if (!"any".equals(poiType))
{ {
PointOfInterestType type = Registry.POINT_OF_INTEREST_TYPE.getOrEmpty(new Identifier(poiType)) PointOfInterestType type = Registry.POINT_OF_INTEREST_TYPE.getOrEmpty(new Identifier(poiType))
.orElseThrow(() -> new ThrowStatement("Unknown POI type", Throwables.UNKNOWN_POI_TYPE)); .orElseThrow(() -> new ThrowStatement(poiType, Throwables.UNKNOWN_POI_TYPE));
condition = (tt) -> tt == type; condition = (tt) -> tt == type;
} }
if (locator.offset + 2 < lv.size()) if (locator.offset + 2 < lv.size())
@@ -394,7 +394,7 @@ public class WorldAccess {
} }
String poiTypeString = poi.getString().toLowerCase(Locale.ROOT); String poiTypeString = poi.getString().toLowerCase(Locale.ROOT);
PointOfInterestType type = Registry.POINT_OF_INTEREST_TYPE.getOrEmpty(new Identifier(poiTypeString)) PointOfInterestType type = Registry.POINT_OF_INTEREST_TYPE.getOrEmpty(new Identifier(poiTypeString))
.orElseThrow(() -> new ThrowStatement("Unknown POI type: "+poiTypeString, Throwables.UNKNOWN_POI_TYPE)); .orElseThrow(() -> new ThrowStatement(poiTypeString, Throwables.UNKNOWN_POI_TYPE));
int occupancy = 0; int occupancy = 0;
if (locator.offset + 1 < lv.size()) if (locator.offset + 1 < lv.size())
{ {
@@ -874,7 +874,7 @@ public class WorldAccess {
playerBreak = true; playerBreak = true;
String itemString = val.getString(); String itemString = val.getString();
item = Registry.ITEM.getOrEmpty(new Identifier(itemString)) item = Registry.ITEM.getOrEmpty(new Identifier(itemString))
.orElseThrow(() -> new ThrowStatement("Incorrect item: " + itemString, Throwables.UNKNOWN_ITEM)); .orElseThrow(() -> new ThrowStatement(itemString, Throwables.UNKNOWN_ITEM));
} }
} }
CompoundTag tag = null; CompoundTag tag = null;
@@ -1182,7 +1182,7 @@ public class WorldAccess {
String biomeName = lv.get(locator.offset+0).evalValue(c).getString(); String biomeName = lv.get(locator.offset+0).evalValue(c).getString();
// from locatebiome command code // from locatebiome command code
Biome biome = cc.s.getMinecraftServer().getRegistryManager().get(Registry.BIOME_KEY).getOrEmpty(new Identifier(biomeName)) Biome biome = cc.s.getMinecraftServer().getRegistryManager().get(Registry.BIOME_KEY).getOrEmpty(new Identifier(biomeName))
.orElseThrow(() -> new ThrowStatement("Unknown biome: "+biomeName, Throwables.UNKNOWN_BIOME)); .orElseThrow(() -> new ThrowStatement(biomeName, Throwables.UNKNOWN_BIOME));
boolean doImmediateUpdate = true; boolean doImmediateUpdate = true;
if (lv.size() > locator.offset+1) if (lv.size() > locator.offset+1)
{ {
@@ -1252,7 +1252,7 @@ public class WorldAccess {
{ {
String reqString = requested.getString(); String reqString = requested.getString();
structure = Registry.STRUCTURE_FEATURE.getOrEmpty(new Identifier(reqString)) structure = Registry.STRUCTURE_FEATURE.getOrEmpty(new Identifier(reqString))
.orElseThrow(() -> new ThrowStatement("Unknown structure: " + reqString, Throwables.UNKNOWN_STRUCTURE)); .orElseThrow(() -> new ThrowStatement(reqString, Throwables.UNKNOWN_STRUCTURE));
} }
if (lv.size() > locator.offset+1) if (lv.size() > locator.offset+1)
{ {
@@ -1332,7 +1332,7 @@ public class WorldAccess {
throw new InternalExpressionException("'set_structure requires at least position and a structure name"); throw new InternalExpressionException("'set_structure requires at least position and a structure name");
String structureName = lv.get(locator.offset).evalValue(c).getString().toLowerCase(Locale.ROOT); String structureName = lv.get(locator.offset).evalValue(c).getString().toLowerCase(Locale.ROOT);
ConfiguredStructureFeature<?, ?> configuredStructure = FeatureGenerator.resolveConfiguredStructure(structureName, world, pos); ConfiguredStructureFeature<?, ?> configuredStructure = FeatureGenerator.resolveConfiguredStructure(structureName, world, pos);
if (configuredStructure == null) throw new ThrowStatement("Unknown structure: "+structureName, Throwables.UNKNOWN_STRUCTURE); if (configuredStructure == null) throw new ThrowStatement(structureName, Throwables.UNKNOWN_STRUCTURE);
// good 'ol pointer // good 'ol pointer
Value[] result = new Value[]{Value.NULL}; Value[] result = new Value[]{Value.NULL};
// technically a world modification. Even if we could let it slide, we will still park it // technically a world modification. Even if we could let it slide, we will still park it
@@ -29,15 +29,15 @@ public class ThrowStatement extends InternalExpressionException
* Conveniently creates a value from the {@code value} String * Conveniently creates a value from the {@code value} String
* to be used easily in Java code * to be used easily in Java code
* @param message The message to display when not handled * @param message The message to display when not handled
* @param thrownExceptionType An {@link Throwables} containing the inheritance data * @param type An {@link Throwables} containing the inheritance data
* for this exception. When throwing from Java, * for this exception. When throwing from Java,
* those exceptions should be pre-registered. * those exceptions should be pre-registered.
*/ */
public ThrowStatement(String message, Throwables thrownExceptionType) public ThrowStatement(String message, Throwables type)
{ {
super(message); super(type.getId());
this.exceptionData = StringValue.of(message); this.exceptionData = StringValue.of(message);
this.thrownExceptionType = thrownExceptionType; this.thrownExceptionType = type;
} }
@Override @Override
@@ -158,7 +158,7 @@ public class ShapeDispatcher
} }
catch (CommandSyntaxException e) catch (CommandSyntaxException e)
{ {
throw new ThrowStatement("No such particle: "+name, Throwables.UNKNOWN_PARTICLE); throw new ThrowStatement(name, Throwables.UNKNOWN_PARTICLE);
} }
particleCache.put(name, particle); particleCache.put(name, particle);
return particle; return particle;
@@ -76,7 +76,7 @@ public class BlockValue extends Value
catch (CommandSyntaxException ignored) catch (CommandSyntaxException ignored)
{ {
} }
throw new ThrowStatement("Cannot parse block: "+str, Throwables.UNKNOWN_BLOCK); throw new ThrowStatement(str, Throwables.UNKNOWN_BLOCK);
} }
public static BlockPos locateBlockPos(CarpetContext c, int xpos, int ypos, int zpos) public static BlockPos locateBlockPos(CarpetContext c, int xpos, int ypos, int zpos)
@@ -299,7 +299,7 @@ public class NBTSerializableValue extends Value implements ContainerValueInterfa
} }
catch (CommandSyntaxException e) catch (CommandSyntaxException e)
{ {
throw new ThrowStatement("Incorrect item: "+itemString, Throwables.UNKNOWN_ITEM); throw new ThrowStatement(itemString, Throwables.UNKNOWN_ITEM);
} }
} }
@@ -160,7 +160,7 @@ public class ValueConversions
} }
} }
if (dim == null) if (dim == null)
throw new ThrowStatement("Incorrect dimension string: "+dimString, Throwables.UNKNOWN_DIMENSION); throw new ThrowStatement(dimString, Throwables.UNKNOWN_DIMENSION);
return server.getWorld(dim); return server.getWorld(dim);
} }
} }