Skip to content

Commit

Permalink
cleanup stacktrace logging for recipe errors (GregTechCEu#2438)
Browse files Browse the repository at this point in the history
  • Loading branch information
TechLord22 authored Apr 2, 2024
1 parent 456c1ae commit 069c586
Show file tree
Hide file tree
Showing 13 changed files with 65 additions and 86 deletions.
9 changes: 7 additions & 2 deletions src/main/java/gregtech/api/recipes/ModHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,12 @@
import org.jetbrains.annotations.Nullable;

import java.lang.reflect.Field;
import java.util.*;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Iterator;
import java.util.Map;
import java.util.Objects;
import java.util.function.Predicate;
import java.util.stream.Collectors;

Expand Down Expand Up @@ -752,6 +757,6 @@ public static boolean setErroredInvalidRecipe(@NotNull String message) throws Il
}

public static void logInvalidRecipe(@NotNull String message) {
GTLog.logger.warn("Invalid Recipe Found", new IllegalArgumentException(message));
GTLog.logger.warn("Invalid Recipe Found: {}", message, new Throwable());
}
}
64 changes: 26 additions & 38 deletions src/main/java/gregtech/api/recipes/RecipeBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -225,8 +225,7 @@ public boolean applyProperty(@NotNull RecipeProperty<?> property, @Nullable Obje

public R input(GTRecipeInput input) {
if (input.getAmount() < 0) {
GTLog.logger.error("Count cannot be less than 0. Actual: {}.", input.getAmount());
GTLog.logger.error("Stacktrace:", new IllegalArgumentException());
GTLog.logger.error("Count cannot be less than 0. Actual: {}.", input.getAmount(), new Throwable());
} else {
this.inputs.add(input);
}
Expand Down Expand Up @@ -295,18 +294,15 @@ public R input(MetaTileEntity mte, int amount) {

public R inputNBT(GTRecipeInput input, NBTMatcher matcher, NBTCondition condition) {
if (input.getAmount() < 0) {
GTLog.logger.error("Count cannot be less than 0. Actual: {}.", input.getAmount());
GTLog.logger.error("Stacktrace:", new IllegalArgumentException());
GTLog.logger.error("Count cannot be less than 0. Actual: {}.", input.getAmount(), new Throwable());
return (R) this;
}
if (matcher == null) {
GTLog.logger.error("NBTMatcher must not be null");
GTLog.logger.error("Stacktrace:", new IllegalArgumentException());
GTLog.logger.error("NBTMatcher must not be null", new Throwable());
return (R) this;
}
if (condition == null) {
GTLog.logger.error("NBTCondition must not be null");
GTLog.logger.error("Stacktrace:", new IllegalArgumentException());
GTLog.logger.error("NBTCondition must not be null", new Throwable());
return (R) this;
}
this.inputs.add(input.setNBTMatchingCondition(matcher, condition));
Expand Down Expand Up @@ -389,8 +385,7 @@ public R inputNBT(@NotNull ItemStack stack, NBTMatcher matcher, NBTCondition con

public R inputs(ItemStack input) {
if (input == null || input.isEmpty()) {
GTLog.logger.error("Input cannot be null or empty. Input: {}", input);
GTLog.logger.error("Stacktrace:", new IllegalArgumentException());
GTLog.logger.error("Input cannot be null or empty. Input: {}", input, new Throwable());
recipeStatus = EnumValidationResult.INVALID;
} else {
this.inputs.add(new GTRecipeItemInput(input));
Expand All @@ -401,8 +396,8 @@ public R inputs(ItemStack input) {
public R inputs(ItemStack... inputs) {
for (ItemStack input : inputs) {
if (input == null || input.isEmpty()) {
GTLog.logger.error("Inputs cannot contain null or empty ItemStacks. Inputs: {}", input);
GTLog.logger.error("Stacktrace:", new IllegalArgumentException());
GTLog.logger.error("Inputs cannot contain null or empty ItemStacks. Inputs: {}", input,
new Throwable());
recipeStatus = EnumValidationResult.INVALID;
continue;
}
Expand All @@ -414,8 +409,7 @@ public R inputs(ItemStack... inputs) {
public R inputStacks(Collection<ItemStack> inputs) {
for (ItemStack input : inputs) {
if (input == null || input.isEmpty()) {
GTLog.logger.error("Input cannot contain null or empty ItemStacks. Inputs: {}", input);
GTLog.logger.error("Stacktrace:", new IllegalArgumentException());
GTLog.logger.error("Input cannot contain null or empty ItemStacks. Inputs: {}", input, new Throwable());
recipeStatus = EnumValidationResult.INVALID;
continue;
}
Expand All @@ -426,8 +420,7 @@ public R inputStacks(Collection<ItemStack> inputs) {

public R inputs(GTRecipeInput input) {
if (input.getAmount() < 0) {
GTLog.logger.error("Input count cannot be less than 0. Actual: {}.", input.getAmount());
GTLog.logger.error("Stacktrace:", new IllegalArgumentException());
GTLog.logger.error("Input count cannot be less than 0. Actual: {}.", input.getAmount(), new Throwable());
recipeStatus = EnumValidationResult.INVALID;
} else {
this.inputs.add(input);
Expand All @@ -438,8 +431,8 @@ public R inputs(GTRecipeInput input) {
public R inputs(GTRecipeInput... inputs) {
for (GTRecipeInput input : inputs) {
if (input.getAmount() < 0) {
GTLog.logger.error("Input count cannot be less than 0. Actual: {}.", input.getAmount());
GTLog.logger.error("Stacktrace:", new IllegalArgumentException());
GTLog.logger.error("Input count cannot be less than 0. Actual: {}.", input.getAmount(),
new Throwable());
recipeStatus = EnumValidationResult.INVALID;
continue;
}
Expand All @@ -451,8 +444,7 @@ public R inputs(GTRecipeInput... inputs) {
public R inputIngredients(Collection<GTRecipeInput> inputs) {
for (GTRecipeInput input : inputs) {
if (input.getAmount() < 0) {
GTLog.logger.error("Count cannot be less than 0. Actual: {}.", input.getAmount());
GTLog.logger.error("Stacktrace:", new IllegalArgumentException());
GTLog.logger.error("Count cannot be less than 0. Actual: {}.", input.getAmount(), new Throwable());
recipeStatus = EnumValidationResult.INVALID;
continue;
}
Expand Down Expand Up @@ -501,8 +493,7 @@ public R notConsumable(FluidStack fluidStack) {
public R circuitMeta(int circuitNumber) {
if (IntCircuitIngredient.CIRCUIT_MIN > circuitNumber || circuitNumber > IntCircuitIngredient.CIRCUIT_MAX) {
GTLog.logger.error("Integrated Circuit Number cannot be less than {} and more than {}",
IntCircuitIngredient.CIRCUIT_MIN, IntCircuitIngredient.CIRCUIT_MAX);
GTLog.logger.error("Stacktrace:", new IllegalArgumentException("Invalid Integrated Circuit Number"));
IntCircuitIngredient.CIRCUIT_MIN, IntCircuitIngredient.CIRCUIT_MAX, new Throwable());
recipeStatus = EnumValidationResult.INVALID;
return (R) this;
}
Expand Down Expand Up @@ -590,8 +581,7 @@ public R fluidInputs(FluidStack input) {
if (input != null && input.amount > 0) {
this.fluidInputs.add(new GTRecipeFluidInput(input));
} else if (input != null) {
GTLog.logger.error("Fluid Input count cannot be less than 0. Actual: {}.", input.amount);
GTLog.logger.error("Stacktrace:", new IllegalArgumentException());
GTLog.logger.error("Fluid Input count cannot be less than 0. Actual: {}.", input.amount, new Throwable());
} else {
GTLog.logger.error("FluidStack cannot be null.");
}
Expand All @@ -604,8 +594,8 @@ public R fluidInputs(FluidStack... fluidStacks) {
if (fluidStack != null && fluidStack.amount > 0) {
fluidIngredients.add(new GTRecipeFluidInput(fluidStack));
} else if (fluidStack != null) {
GTLog.logger.error("Fluid Input count cannot be less than 0. Actual: {}.", fluidStack.amount);
GTLog.logger.error("Stacktrace:", new IllegalArgumentException());
GTLog.logger.error("Fluid Input count cannot be less than 0. Actual: {}.", fluidStack.amount,
new Throwable());
} else {
GTLog.logger.error("FluidStack cannot be null.");
}
Expand Down Expand Up @@ -648,8 +638,7 @@ public R chancedOutput(ItemStack stack, int chance, int tierChanceBoost) {
}
if (0 >= chance || chance > ChancedOutputLogic.getMaxChancedValue()) {
GTLog.logger.error("Chance cannot be less or equal to 0 or more than {}. Actual: {}.",
ChancedOutputLogic.getMaxChancedValue(), chance);
GTLog.logger.error("Stacktrace:", new IllegalArgumentException());
ChancedOutputLogic.getMaxChancedValue(), chance, new Throwable());
recipeStatus = EnumValidationResult.INVALID;
return (R) this;
}
Expand Down Expand Up @@ -696,8 +685,7 @@ public R chancedFluidOutput(FluidStack stack, int chance, int tierChanceBoost) {
}
if (0 >= chance || chance > ChancedOutputLogic.getMaxChancedValue()) {
GTLog.logger.error("Chance cannot be less or equal to 0 or more than {}. Actual: {}.",
ChancedOutputLogic.getMaxChancedValue(), chance);
GTLog.logger.error("Stacktrace:", new IllegalArgumentException());
ChancedOutputLogic.getMaxChancedValue(), chance, new Throwable());
recipeStatus = EnumValidationResult.INVALID;
return (R) this;
}
Expand Down Expand Up @@ -934,31 +922,31 @@ protected EnumValidationResult validate() {
return msg.postIfNotEmpty() ? EnumValidationResult.SKIP : EnumValidationResult.VALID;
}
if (EUt == 0) {
GTLog.logger.error("EU/t cannot be equal to 0", new IllegalArgumentException());
GTLog.logger.error("EU/t cannot be equal to 0", new Throwable());
if (isCTRecipe) {
CraftTweakerAPI.logError("EU/t cannot be equal to 0", new IllegalArgumentException());
CraftTweakerAPI.logError("EU/t cannot be equal to 0", new Throwable());
}
recipeStatus = EnumValidationResult.INVALID;
}
if (duration <= 0) {
GTLog.logger.error("Duration cannot be less or equal to 0", new IllegalArgumentException());
GTLog.logger.error("Duration cannot be less or equal to 0", new Throwable());
if (isCTRecipe) {
CraftTweakerAPI.logError("Duration cannot be less or equal to 0", new IllegalArgumentException());
CraftTweakerAPI.logError("Duration cannot be less or equal to 0", new Throwable());
}
recipeStatus = EnumValidationResult.INVALID;
}
if (recipeMap != null) { // recipeMap can be null in tests
if (category == null) {
GTLog.logger.error("Recipes must have a category", new IllegalArgumentException());
GTLog.logger.error("Recipes must have a category", new Throwable());
if (isCTRecipe) {
CraftTweakerAPI.logError("Recipes must have a category", new IllegalArgumentException());
CraftTweakerAPI.logError("Recipes must have a category", new Throwable());
}
recipeStatus = EnumValidationResult.INVALID;
} else if (category.getRecipeMap() != this.recipeMap) {
GTLog.logger.error("Cannot apply Category with incompatible RecipeMap", new IllegalArgumentException());
GTLog.logger.error("Cannot apply Category with incompatible RecipeMap", new Throwable());
if (isCTRecipe) {
CraftTweakerAPI.logError("Cannot apply Category with incompatible RecipeMap",
new IllegalArgumentException());
new Throwable());
}
recipeStatus = EnumValidationResult.INVALID;
}
Expand Down
43 changes: 17 additions & 26 deletions src/main/java/gregtech/api/recipes/RecipeMap.java
Original file line number Diff line number Diff line change
Expand Up @@ -462,79 +462,70 @@ protected ValidationResult<Recipe> postValidateRecipe(@NotNull ValidationResult<

boolean emptyInputs = recipe.getInputs().isEmpty() && recipe.getFluidInputs().isEmpty();
if (emptyInputs) {
GTLog.logger.error("Invalid amount of recipe inputs. Recipe inputs are empty.");
GTLog.logger.error("Stacktrace:", new IllegalArgumentException("Invalid number of Inputs"));
GTLog.logger.error("Invalid amount of recipe inputs. Recipe inputs are empty.", new Throwable());
if (recipe.getIsCTRecipe()) {
CraftTweakerAPI.logError("Invalid amount of recipe inputs. Recipe inputs are empty.");
CraftTweakerAPI.logError("Stacktrace:", new IllegalArgumentException("Invalid number of Inputs"));
CraftTweakerAPI.logError("Invalid amount of recipe inputs. Recipe inputs are empty.", new Throwable());
}
recipeStatus = EnumValidationResult.INVALID;
}
boolean emptyOutputs = !this.allowEmptyOutput && recipe.getEUt() > 0 && recipe.getOutputs().isEmpty() &&
recipe.getFluidOutputs().isEmpty() && recipe.getChancedOutputs().getChancedEntries().isEmpty() &&
recipe.getChancedFluidOutputs().getChancedEntries().isEmpty();
if (emptyOutputs) {
GTLog.logger.error("Invalid amount of recipe outputs. Recipe outputs are empty.");
GTLog.logger.error("Stacktrace:", new IllegalArgumentException("Invalid number of Outputs"));
GTLog.logger.error("Invalid amount of recipe outputs. Recipe outputs are empty.", new Throwable());
if (recipe.getIsCTRecipe()) {
CraftTweakerAPI.logError("Invalid amount of outputs inputs. Recipe outputs are empty.");
CraftTweakerAPI.logError("Stacktrace:", new IllegalArgumentException("Invalid number of Outputs"));
CraftTweakerAPI.logError("Invalid amount of outputs inputs. Recipe outputs are empty.",
new Throwable());
}
recipeStatus = EnumValidationResult.INVALID;
}

int amount = recipe.getInputs().size();
if (amount > getMaxInputs()) {
GTLog.logger.error("Invalid amount of recipe inputs. Actual: {}. Should be at most {}.", amount,
getMaxInputs());
GTLog.logger.error("Stacktrace:", new IllegalArgumentException("Invalid number of Inputs"));
getMaxInputs(), new Throwable());
if (recipe.getIsCTRecipe()) {
CraftTweakerAPI.logError(String.format(
"Invalid amount of recipe inputs. Actual: %s. Should be at most %s.", amount, getMaxInputs()));
CraftTweakerAPI.logError("Stacktrace:", new IllegalArgumentException("Invalid number of Inputs"));
"Invalid amount of recipe inputs. Actual: %s. Should be at most %s.", amount, getMaxInputs()),
new Throwable());
}
recipeStatus = EnumValidationResult.INVALID;
}

amount = recipe.getOutputs().size() + recipe.getChancedOutputs().getChancedEntries().size();
if (amount > getMaxOutputs()) {
GTLog.logger.error("Invalid amount of recipe outputs. Actual: {}. Should be at most {}.", amount,
getMaxOutputs());
GTLog.logger.error("Stacktrace:", new IllegalArgumentException("Invalid number of Outputs"));
getMaxOutputs(), new Throwable());
if (recipe.getIsCTRecipe()) {
CraftTweakerAPI
.logError(String.format("Invalid amount of recipe outputs. Actual: %s. Should be at most %s.",
amount, getMaxOutputs()));
CraftTweakerAPI.logError("Stacktrace:", new IllegalArgumentException("Invalid number of Outputs"));
amount, getMaxOutputs()), new Throwable());
}
recipeStatus = EnumValidationResult.INVALID;
}

amount = recipe.getFluidInputs().size();
if (amount > getMaxFluidInputs()) {
GTLog.logger.error("Invalid amount of recipe fluid inputs. Actual: {}. Should be at most {}.", amount,
getMaxFluidInputs());
GTLog.logger.error("Stacktrace:", new IllegalArgumentException("Invalid number of Fluid Inputs"));
getMaxFluidInputs(), new Throwable());
if (recipe.getIsCTRecipe()) {
CraftTweakerAPI.logError(
String.format("Invalid amount of recipe fluid inputs. Actual: %s. Should be at most %s.",
amount, getMaxFluidInputs()));
CraftTweakerAPI.logError("Stacktrace:", new IllegalArgumentException("Invalid number of Fluid Inputs"));
amount, getMaxFluidInputs()),
new Throwable());
}
recipeStatus = EnumValidationResult.INVALID;
}

amount = recipe.getFluidOutputs().size() + recipe.getChancedFluidOutputs().getChancedEntries().size();
if (amount > getMaxFluidOutputs()) {
GTLog.logger.error("Invalid amount of recipe fluid outputs. Actual: {}. Should be at most {}.", amount,
getMaxFluidOutputs());
GTLog.logger.error("Stacktrace:", new IllegalArgumentException("Invalid number of Fluid Outputs"));
getMaxFluidOutputs(), new Throwable());
if (recipe.getIsCTRecipe()) {
CraftTweakerAPI.logError(
String.format("Invalid amount of recipe fluid outputs. Actual: %s. Should be at most %s.",
amount, getMaxFluidOutputs()));
CraftTweakerAPI.logError("Stacktrace:",
new IllegalArgumentException("Invalid number of Fluid Outputs"));
amount, getMaxFluidOutputs()),
new Throwable());
}
recipeStatus = EnumValidationResult.INVALID;
}
Expand Down Expand Up @@ -1008,7 +999,7 @@ private boolean recurseIngredientTreeAdd(@NotNull Recipe recipe,
@NotNull Branch branchMap, int index, int count) {
if (count >= ingredients.size()) return true;
if (index >= ingredients.size()) {
throw new RuntimeException("Index out of bounds for recurseItemTreeAdd, should not happen");
throw new IllegalStateException("Index out of bounds for recurseItemTreeAdd, should not happen");
}
// Loop through NUMBER_OF_INGREDIENTS times.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,14 +58,14 @@ public boolean applyProperty(@NotNull String key, @Nullable Object value) {
private boolean applyResearchProperty(ResearchPropertyData.ResearchEntry researchEntry) {
if (!ConfigHolder.machines.enableResearch) return false;
if (researchEntry == null) {
GTLog.logger.error("Assembly Line Research Entry cannot be empty.", new IllegalArgumentException());
GTLog.logger.error("Assembly Line Research Entry cannot be empty.", new Throwable());
recipeStatus = EnumValidationResult.INVALID;
return false;
}

if (!generatingRecipes) {
GTLog.logger.error("Cannot generate recipes when using researchWithoutRecipe()",
new IllegalArgumentException());
new Throwable());
recipeStatus = EnumValidationResult.INVALID;
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public boolean applyProperty(@NotNull String key, Object value) {
public BlastRecipeBuilder blastFurnaceTemp(int blastFurnaceTemp) {
if (blastFurnaceTemp <= 0) {
GTLog.logger.error("Blast Furnace Temperature cannot be less than or equal to 0",
new IllegalArgumentException());
new Throwable());
recipeStatus = EnumValidationResult.INVALID;
}
this.applyProperty(TemperatureProperty.getInstance(), blastFurnaceTemp);
Expand Down
Loading

0 comments on commit 069c586

Please sign in to comment.