From 9cf7f1eddefd9076178c2d92c309d650f93cefda Mon Sep 17 00:00:00 2001 From: Rsl1122 Date: Sat, 3 Mar 2018 16:37:50 +0200 Subject: [PATCH] Better Enable error logging. Solves #509 --- .../src/main/java/com/djrapitops/plan/Plan.java | 15 ++++++++++++++- .../java/com/djrapitops/plan/PlanBungee.java | 17 +++++++++++++++-- .../com/djrapitops/plan/system/PlanSystem.java | 2 +- .../plan/system/database/DBSystem.java | 3 ++- .../system/info/server/BukkitServerInfo.java | 3 ++- .../system/info/server/BungeeServerInfo.java | 2 +- 6 files changed, 35 insertions(+), 7 deletions(-) diff --git a/Plan/src/main/java/com/djrapitops/plan/Plan.java b/Plan/src/main/java/com/djrapitops/plan/Plan.java index 6dbac642f..bf2187e5b 100644 --- a/Plan/src/main/java/com/djrapitops/plan/Plan.java +++ b/Plan/src/main/java/com/djrapitops/plan/Plan.java @@ -19,6 +19,7 @@ */ package com.djrapitops.plan; +import com.djrapitops.plan.api.exceptions.EnableException; import com.djrapitops.plan.command.PlanCommand; import com.djrapitops.plan.system.BukkitSystem; import com.djrapitops.plan.system.processing.importing.ImporterManager; @@ -35,6 +36,9 @@ import com.djrapitops.plugin.api.utility.log.Log; import com.djrapitops.plugin.settings.ColorScheme; import org.bukkit.configuration.file.FileConfiguration; +import java.util.logging.Level; +import java.util.logging.Logger; + /** * Main class for Bukkit that manages the plugin. * @@ -76,9 +80,18 @@ public class Plan extends BukkitPlugin implements PlanPlugin { Benchmark.stop("Enable", "Enable"); Log.logDebug("Enable"); Log.info(Locale.get(Msg.ENABLED).toString()); + } catch (AbstractMethodError e) { + Log.error("Plugin ran into AbstractMethodError - Server restart is required. Likely cause is updating the jar without a restart."); + } catch (EnableException e) { + Log.error("Plugin Failed to Initialize Correctly. If this issue is caused by config settings you can use /plan reload"); + Log.error("----------------------------------------"); + Log.error("Error: " + e.getMessage()); + Log.error("----------------------------------------"); + onDisable(); } catch (Exception e) { Log.error("Plugin Failed to Initialize Correctly. If this issue is caused by config settings you can use /plan reload"); - Log.toLog(this.getClass(), e); + Log.error("This error should be reported at https://github.com/Rsl1122/Plan-PlayerAnalytics/issues"); + Logger.getGlobal().log(Level.SEVERE, this.getClass().getSimpleName() + "-v" + getVersion(), e); onDisable(); } registerCommand("plan", new PlanCommand(this)); diff --git a/Plan/src/main/java/com/djrapitops/plan/PlanBungee.java b/Plan/src/main/java/com/djrapitops/plan/PlanBungee.java index 5cb9a593e..c0a65ee1b 100644 --- a/Plan/src/main/java/com/djrapitops/plan/PlanBungee.java +++ b/Plan/src/main/java/com/djrapitops/plan/PlanBungee.java @@ -4,6 +4,7 @@ */ package com.djrapitops.plan; +import com.djrapitops.plan.api.exceptions.EnableException; import com.djrapitops.plan.command.PlanBungeeCommand; import com.djrapitops.plan.system.BungeeSystem; import com.djrapitops.plan.system.settings.locale.Locale; @@ -17,6 +18,8 @@ import com.djrapitops.plugin.api.utility.log.Log; import com.djrapitops.plugin.settings.ColorScheme; import java.io.InputStream; +import java.util.logging.Level; +import java.util.logging.Logger; /** * Bungee Main class. @@ -39,9 +42,19 @@ public class PlanBungee extends BungeePlugin implements PlanPlugin { system.enable(); Log.info(Locale.get(Msg.ENABLED).toString()); + } catch (AbstractMethodError e) { + Log.error("Plugin ran into AbstractMethodError - Server restart is required. Likely cause is updating the jar without a restart."); + } catch (EnableException e) { + Log.error("Plugin Failed to Initialize Correctly. If this issue is caused by config settings you can use /planbungee reload"); + Log.error("----------------------------------------"); + Log.error("Error: " + e.getMessage()); + Log.error("----------------------------------------"); + onDisable(); } catch (Exception e) { - Log.error("Plugin Failed to Initialize Correctly:"); - Log.toLog(this.getClass(), e); + Log.error("Plugin Failed to Initialize Correctly. If this issue is caused by config settings you can use /planbungee reload"); + Log.error("This error should be reported at https://github.com/Rsl1122/Plan-PlayerAnalytics/issues"); + Logger.getGlobal().log(Level.SEVERE, this.getClass().getSimpleName() + "-v" + getVersion(), e); + onDisable(); } registerCommand("planbungee", new PlanBungeeCommand(this)); } diff --git a/Plan/src/main/java/com/djrapitops/plan/system/PlanSystem.java b/Plan/src/main/java/com/djrapitops/plan/system/PlanSystem.java index 5cd4d46e6..6c6ef892e 100644 --- a/Plan/src/main/java/com/djrapitops/plan/system/PlanSystem.java +++ b/Plan/src/main/java/com/djrapitops/plan/system/PlanSystem.java @@ -136,7 +136,7 @@ public abstract class PlanSystem implements SubSystem { Verify.nullCheck(hookHandler, () -> new IllegalStateException("Plugin Hooks were not initialized.")); Verify.nullCheck(planAPI, () -> new IllegalStateException("Plan API was not initialized.")); } catch (Exception e) { - throw new EnableException("One of the subsystems is not initialized on enable for " + this.getClass().getSimpleName() + ".", e); + throw new EnableException("One of the subsystems is not initialized on enable for " + this.getClass().getSimpleName() + ": " + e.getMessage()); } } diff --git a/Plan/src/main/java/com/djrapitops/plan/system/database/DBSystem.java b/Plan/src/main/java/com/djrapitops/plan/system/database/DBSystem.java index d0bf54c71..54cbd3472 100644 --- a/Plan/src/main/java/com/djrapitops/plan/system/database/DBSystem.java +++ b/Plan/src/main/java/com/djrapitops/plan/system/database/DBSystem.java @@ -49,7 +49,8 @@ public abstract class DBSystem implements SubSystem { Log.info(Locale.get(Msg.ENABLE_DB_INFO).parse(db.getConfigName())); Benchmark.stop("Enable", "Init Database"); } catch (DBInitException e) { - throw new EnableException("Database failed to initialize", e); + Throwable cause = e.getCause(); + throw new EnableException(db.getName() + " init failure: " + cause.getMessage(), cause); } } diff --git a/Plan/src/main/java/com/djrapitops/plan/system/info/server/BukkitServerInfo.java b/Plan/src/main/java/com/djrapitops/plan/system/info/server/BukkitServerInfo.java index 36111c66d..7bcaa5d46 100644 --- a/Plan/src/main/java/com/djrapitops/plan/system/info/server/BukkitServerInfo.java +++ b/Plan/src/main/java/com/djrapitops/plan/system/info/server/BukkitServerInfo.java @@ -51,7 +51,8 @@ public class BukkitServerInfo extends ServerInfo { try { return serverUUID.isPresent() ? updateDbInfo(serverUUID.get()) : registerServer(); } catch (DBException e) { - throw new EnableException("Failed to read Server information from Database", e); + String causeMsg = e.getCause().getMessage(); + throw new EnableException("Failed to read Server information from Database: " + causeMsg, e); } catch (IOException e) { throw new EnableException("Failed to read ServerInfoFile.yml", e); } diff --git a/Plan/src/main/java/com/djrapitops/plan/system/info/server/BungeeServerInfo.java b/Plan/src/main/java/com/djrapitops/plan/system/info/server/BungeeServerInfo.java index f29091c83..14b0b1606 100644 --- a/Plan/src/main/java/com/djrapitops/plan/system/info/server/BungeeServerInfo.java +++ b/Plan/src/main/java/com/djrapitops/plan/system/info/server/BungeeServerInfo.java @@ -39,7 +39,7 @@ public class BungeeServerInfo extends ServerInfo { server = registerBungeeInfo(db); } } catch (DBException e) { - throw new EnableException("Failed to read Database for Server"); + throw new EnableException("Failed to read Server information from Database."); } return server; }