Skip to content

Commit

Permalink
Cleaner exception messages
Browse files Browse the repository at this point in the history
  • Loading branch information
Srdjan-V committed Oct 23, 2022
1 parent e35b1cc commit 47396e0
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public static void validateState() {
commonRuntimeCheck(loggers);
}

commonLog(loggers);
commonLog(loggers, false);

//Remove startup error loggers, and keep only runtime
iCustomLoggerPool.removeIf(ICustomLogger::discardLoggerAfterStartup);
Expand All @@ -45,19 +45,33 @@ public static void runtimeErrorLogging() throws PowerTierNotFound {
List<ICustomLogger> loggers = new ArrayList<>();
commonRuntimeCheck(loggers);

if (!commonLog(loggers)) {
if (!commonLog(loggers, true)) {
TweakedLib.LOGGER.warn("Runtime error reporting was called, but no errors where found");
return;
}

throw new PowerTierNotFound("Check the logs");
List<String> errors = new ArrayList<>();

for (ICustomLogger logger : loggers) {
errors.addAll(logger.getErrors());
logger.clean();//prevent memory leak with loliasm/vanilafix installed
}

throw new PowerTierNotFound(errors);
}

private static boolean commonLog(List<ICustomLogger> loggers) {
private static boolean commonLog(List<ICustomLogger> loggers, boolean isRuntime) {
if (loggers.isEmpty()) {
return false;
}

if (isRuntime) {
for (ICustomLogger c : loggers) {
logSetting(c);
}
return true;
}

for (ICustomLogger c : loggers) {
loggAll(c);
c.clean();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,25 @@
package srki2k.tweakedlib.api.logging.errorlogginglib;

import java.util.List;

public class PowerTierNotFound extends RuntimeException {
public PowerTierNotFound(String check_the_logs) {
super(check_the_logs);
private final List<String> missingPowerTiers;

public PowerTierNotFound(List<String> missingPowerTiers) {
this.missingPowerTiers = missingPowerTiers;
}

@Override
public String getMessage() {
StringBuilder stringBuilder = new StringBuilder(missingPowerTiers.size());

stringBuilder.append(System.lineSeparator());
stringBuilder.append(" ====================== Missing Power Tiers ======================");
stringBuilder.append(System.lineSeparator());
for (String error : missingPowerTiers) {
stringBuilder.append(" ").append(error).append(System.lineSeparator());
}
return stringBuilder.toString();

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public final class PowerTierHandler {
//A fallback power tier instead of returning null or power tier 0
fallback = new PowerTier(Integer.MAX_VALUE, 0);
fallbackHashCode = fallback.hashCode();
powerTierMap.put(fallback.hashCode(), fallback);
powerTierMap.put(fallbackHashCode, fallback);
}

public static void recalculateTiers() {
Expand All @@ -44,7 +44,7 @@ public static int registerPowerTier(int capacity, int rft) {
int hash = powerTier.hashCode();

powerTierMap.put(hash, powerTier);
return powerTier.hashCode();
return hash;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public static int registerPowerTier(int capacity, int rft) {
isValid = false;
}

int powerTier = PowerTierHandler.registerPowerTier(capacity, rft);
int powerTier = PowerTierHandler.registerPowerTier(capacity, rft);
if (powerTier != PowerTierHandler.getFallbackPowerTierHashCode() && isValid) {
CraftTweakerAPI.logInfo("Added powerTier with capacity: " + capacity + " and " + rft + " RF/t");
return powerTier;
Expand Down

0 comments on commit 47396e0

Please sign in to comment.