Skip to content

Commit

Permalink
- tweak feature debugger and catch any exceptions thrown during debug…
Browse files Browse the repository at this point in the history
…ging
  • Loading branch information
dags- committed Apr 30, 2020
1 parent 5af4aff commit 0da0d13
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 165 deletions.
49 changes: 39 additions & 10 deletions src/main/java/com/terraforged/feature/util/FeatureDebugger.java
Expand Up @@ -20,11 +20,23 @@ public class FeatureDebugger {

public static List<String> getErrors(ConfiguredFeature<?, ?> feature) {
List<String> errors = new ArrayList<>();
checkConfiguredFeature(feature, errors);
try {
checkConfiguredFeature(feature, errors);
} catch (Throwable t) {
errors.add(
"Exception thrown whilst debugging biome feature: " + feature + " (this is bad)"
+ "\nError message:"
+ "\n" + t.getMessage()
);
}
return errors;
}

private static void checkConfiguredFeature(ConfiguredFeature<?, ?> feature, List<String> errors) {
if (!isValid(feature, errors)) {
return;
}

if (feature.config instanceof DecoratedFeatureConfig) {
decorated((DecoratedFeatureConfig) feature.config, errors);
return;
Expand All @@ -50,14 +62,11 @@ private static void checkConfiguredFeature(ConfiguredFeature<?, ?> feature, List
multiChance((MultipleWithChanceRandomFeatureConfig) feature.config, errors);
return;
}

checkFeature(feature.feature, errors);
checkConfig(feature.config, errors);
}

private static void decorated(DecoratedFeatureConfig config, List<String> errors) {
checkConfiguredFeature(config.feature, errors);
checkDecorator(config.decorator, errors);
isValid(config.decorator, errors);
}

private static void single(SingleRandomFeature config, List<String> errors) {
Expand All @@ -83,47 +92,67 @@ private static void multiChance(MultipleWithChanceRandomFeatureConfig config, Li
}
}

private static void checkFeature(Feature<?> feature, List<String> list) {
private static boolean isValid(ConfiguredFeature<?, ?> feature, List<String> list) {
if (feature == null) {
list.add("null configured feature (this is bad! D: )");
return false;
}
return isValid(feature.feature, list) && isValid(feature.config, list);
}

private static boolean isValid(Feature<?> feature, List<String> list) {
if (feature == null) {
list.add("null feature");
return false;
} else if (!ForgeRegistries.FEATURES.containsValue(feature)) {
list.add("unregistered feature: " + feature.getClass().getName());
return false;
}
return true;
}

private static void checkConfig(IFeatureConfig config, List<String> list) {
private static boolean isValid(IFeatureConfig config, List<String> list) {
if (config == null) {
list.add("null config");
return;
return false;
}

try {
config.serialize(JsonOps.INSTANCE);
return true;
} catch (Throwable t) {
list.add("config: " + config.getClass().getName() + ", error: " + t.getMessage());
return false;
}
}

private static void checkDecorator(ConfiguredPlacement<?> decorator, List<String> list) {
private static boolean isValid(ConfiguredPlacement<?> decorator, List<String> list) {
if (decorator == null) {
list.add("null configured placement");
return;
return false;
}

boolean valid = true;
if (decorator.decorator == null) {
list.add("null placement");
valid = false;
} else if (!ForgeRegistries.DECORATORS.containsValue(decorator.decorator)) {
list.add("unregistered placement: " + decorator.decorator.getClass().getName());
valid = false;
}

if (decorator.config == null) {
list.add("null decorator config");
valid = false;
} else {
try {
decorator.config.serialize(JsonOps.INSTANCE);
} catch (Throwable t) {
valid = false;
list.add("placement config: " + decorator.config.getClass().getName() + ", error: " + t.getMessage());
}
}

return valid;
}
}
155 changes: 0 additions & 155 deletions src/main/java/com/terraforged/feature/util/FeatureException.java

This file was deleted.

0 comments on commit 0da0d13

Please sign in to comment.