Add a configuration to print jdbc exceptions

By default, mcmmo tries to pretty print errors, which is fine for many cases,
however; deeper nested errors can lack information, e.g. networking related issues,
while the pretty print is less intimitating and provides useful information to users,
surpressing the trace can prevent debugging these deeper issues, this config option serves
as a compromise between scaring users and having a means to find these deeper issues.
This commit is contained in:
Shane Freeder 2019-08-26 05:29:29 +01:00
parent 8951c1fd21
commit 8a4410cde8
No known key found for this signature in database
GPG Key ID: A3F61EA5A085289C
3 changed files with 10 additions and 0 deletions

View File

@ -341,6 +341,7 @@ public class Config extends AutoUpdateConfigLoader {
public int getMySQLMaxConnections(PoolIdentifier identifier) { return config.getInt("MySQL.Database.MaxConnections." + StringUtils.getCapitalized(identifier.toString()), 30); }
public int getMySQLMaxPoolSize(PoolIdentifier identifier) { return config.getInt("MySQL.Database.MaxPoolSize." + StringUtils.getCapitalized(identifier.toString()), 10); }
public boolean getMySQLSSL() { return config.getBoolean("MySQL.Server.SSL", true); }
public boolean getMySQLDebug() { return config.getBoolean("MySQL.Debug", false); }
private String getStringIncludingInts(String key) {
String str = config.getString(key);

View File

@ -31,6 +31,8 @@ public final class SQLDatabaseManager implements DatabaseManager {
private DataSource loadPool;
private DataSource savePool;
private boolean debug = false;
private ReentrantLock massUpdateLock = new ReentrantLock();
protected SQLDatabaseManager() {
@ -56,6 +58,8 @@ public final class SQLDatabaseManager implements DatabaseManager {
//throw e; // aborts onEnable() Riking if you want to do this, fully implement it.
}
debug = Config.getInstance().getMySQLDebug();
PoolProperties poolProperties = new PoolProperties();
poolProperties.setDriverClassName("com.mysql.jdbc.Driver");
@ -1148,6 +1152,10 @@ public final class SQLDatabaseManager implements DatabaseManager {
}
private void printErrors(SQLException ex) {
if (debug) {
ex.printStackTrace();
}
StackTraceElement element = ex.getStackTrace()[0];
mcMMO.p.getLogger().severe("Location: " + element.getClassName() + " " + element.getMethodName() + " " + element.getLineNumber());
mcMMO.p.getLogger().severe("SQLException: " + ex.getMessage());

View File

@ -146,6 +146,7 @@ Backups:
###
MySQL:
Enabled: false
Debug: false
Database:
User_Name: UserName
User_Password: UserPassword