Better Enable error logging. Solves #509

This commit is contained in:
Rsl1122 2018-03-03 16:37:50 +02:00
parent 5ef1771fd4
commit 9cf7f1edde
6 changed files with 35 additions and 7 deletions

View File

@ -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));

View File

@ -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));
}

View File

@ -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());
}
}

View File

@ -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);
}
}

View File

@ -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);
}

View File

@ -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;
}