Cleanup: Properly log errors

This commit is contained in:
Phoenix616 2023-03-01 18:27:04 +01:00
parent 7a09c53bde
commit 92a013dd10
No known key found for this signature in database
GPG Key ID: 40E2321E71738EB0
8 changed files with 24 additions and 18 deletions

View File

@ -1,9 +1,10 @@
package com.Acrobot.Breeze.Configuration; package com.Acrobot.Breeze.Configuration;
import com.Acrobot.Breeze.Configuration.Annotations.ConfigurationComment; import com.Acrobot.Breeze.Configuration.Annotations.ConfigurationComment;
import com.Acrobot.Breeze.Configuration.Annotations.Parser;
import java.lang.reflect.Field; import java.lang.reflect.Field;
import java.util.logging.Level;
import java.util.logging.Logger;
/** /**
* @author Acrobot * @author Acrobot
@ -29,7 +30,7 @@ public class FieldParser {
try { try {
builder.append(field.getName()).append(": ").append(parser.parseToYAML(field.get(null))); builder.append(field.getName()).append(": ").append(parser.parseToYAML(field.get(null)));
} catch (IllegalAccessException e) { } catch (IllegalAccessException e) {
e.printStackTrace(); Logger.getLogger("FieldParser").log(Level.SEVERE, "Error while parsing field", e);
return ""; return "";
} }

View File

@ -1,8 +1,12 @@
package com.Acrobot.Breeze.Database; package com.Acrobot.Breeze.Database;
import com.Acrobot.ChestShop.ChestShop;
import java.sql.Connection; import java.sql.Connection;
import java.sql.DriverManager; import java.sql.DriverManager;
import java.sql.SQLException; import java.sql.SQLException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.persistence.Entity; import javax.persistence.Entity;
@ -60,7 +64,7 @@ public class Database {
try { try {
table.create(fields); table.create(fields);
} catch (SQLException e) { } catch (SQLException e) {
e.printStackTrace(); Logger.getLogger("Database").log(Level.SEVERE, "Error while creating database from " + clazz.getName() + " (" + fields + ")", e);
return false; return false;
} }

View File

@ -1,6 +1,8 @@
package com.Acrobot.Breeze.Database; package com.Acrobot.Breeze.Database;
import java.util.*; import java.util.*;
import java.util.logging.Level;
import java.util.logging.Logger;
/** /**
* A class representing a Row in SQL query * A class representing a Row in SQL query
@ -85,21 +87,16 @@ public class Row {
try { try {
object = clazz.newInstance(); object = clazz.newInstance();
} catch (InstantiationException e) { } catch (InstantiationException | IllegalAccessException e) {
e.printStackTrace(); Logger.getLogger("Row").log(Level.SEVERE, "Error while creating new instance of class " + clazz.getName() + " for row", e);
return null;
} catch (IllegalAccessException e) {
e.printStackTrace();
return null; return null;
} }
for (Map.Entry<String, String> value : values.entrySet()) { for (Map.Entry<String, String> value : values.entrySet()) {
try { try {
clazz.getDeclaredField(value.getKey()).set(object, value.getValue()); clazz.getDeclaredField(value.getKey()).set(object, value.getValue());
} catch (NoSuchFieldException ex) { } catch (NoSuchFieldException | IllegalAccessException ex) {
ex.printStackTrace(); Logger.getLogger("Row").log(Level.SEVERE, "Error while setting field " + value.getKey() + " to " + value.getValue() + " of class " + clazz.getName(), ex);
} catch (IllegalAccessException ex) {
ex.printStackTrace();
} }
} }

View File

@ -137,7 +137,7 @@ public class Migrations {
try { try {
items.executeRawNoArgs("INSERT INTO `items` (id, code) SELECT id, code uuid FROM `items-old`"); items.executeRawNoArgs("INSERT INTO `items` (id, code) SELECT id, code uuid FROM `items-old`");
} catch (SQLException e) { } catch (SQLException e) {
e.printStackTrace(); ChestShop.getBukkitLogger().log(Level.SEVERE, "Error while inserting items into new database while migrating to v4", e);
} }
ChestShop.getBukkitLogger().log(Level.INFO, "Migration of items table finished in " + (System.currentTimeMillis() - start) / 1000.0 + "s!"); ChestShop.getBukkitLogger().log(Level.INFO, "Migration of items table finished in " + (System.currentTimeMillis() - start) / 1000.0 + "s!");

View File

@ -17,6 +17,7 @@ import java.io.IOException;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.util.HashSet; import java.util.HashSet;
import java.util.Set; import java.util.Set;
import java.util.logging.Level;
import static com.Acrobot.ChestShop.Events.TransactionEvent.TransactionType.BUY; import static com.Acrobot.ChestShop.Events.TransactionEvent.TransactionType.BUY;
@ -44,7 +45,7 @@ public class DiscountModule implements Listener {
try { try {
config.save(ChestShop.loadFile("discounts.yml")); config.save(ChestShop.loadFile("discounts.yml"));
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); ChestShop.getBukkitLogger().log(Level.SEVERE, "Error while loading discounts config", e);
} }
groupList = config.getKeys(false); groupList = config.getKeys(false);

View File

@ -16,6 +16,7 @@ import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.util.Locale; import java.util.Locale;
import java.util.Map; import java.util.Map;
import java.util.logging.Level;
import static com.Acrobot.Breeze.Utils.StringUtil.getMinecraftStringWidth; import static com.Acrobot.Breeze.Utils.StringUtil.getMinecraftStringWidth;
@ -51,7 +52,7 @@ public class ItemAliasModule implements Listener {
configuration.options().copyDefaults(true); configuration.options().copyDefaults(true);
configuration.save(ChestShop.loadFile("itemAliases.yml")); configuration.save(ChestShop.loadFile("itemAliases.yml"));
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); ChestShop.getBukkitLogger().log(Level.SEVERE, "Error while saving item aliases config", e);
} }
} }

View File

@ -11,6 +11,8 @@ import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority; import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
import java.util.logging.Level;
import static com.Acrobot.ChestShop.Permission.OTHER_NAME_CREATE; import static com.Acrobot.ChestShop.Permission.OTHER_NAME_CREATE;
import static com.Acrobot.ChestShop.Signs.ChestShopSign.NAME_LINE; import static com.Acrobot.ChestShop.Signs.ChestShopSign.NAME_LINE;
import static com.Acrobot.ChestShop.Events.PreShopCreationEvent.CreationOutcome.UNKNOWN_PLAYER; import static com.Acrobot.ChestShop.Events.PreShopCreationEvent.CreationOutcome.UNKNOWN_PLAYER;
@ -58,7 +60,7 @@ public class NameChecker implements Listener {
} }
} }
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); ChestShop.getBukkitLogger().log(Level.SEVERE, "Error while trying to check account for name " + name + " with player " + player.getName(), e);
} }
} }
event.setOwnerAccount(account); event.setOwnerAccount(account);

View File

@ -43,7 +43,7 @@ public class ItemDatabase {
itemDao = DaoCreator.getDaoAndCreateTable(Item.class); itemDao = DaoCreator.getDaoAndCreateTable(Item.class);
handleMetadataUpdate(); handleMetadataUpdate();
} catch (SQLException e) { } catch (SQLException e) {
e.printStackTrace(); ChestShop.getBukkitLogger().log(Level.SEVERE, "Error while loading items database", e);
} }
} }
@ -59,7 +59,7 @@ public class ItemDatabase {
try { try {
versionConfig.save(configFile); versionConfig.save(configFile);
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); ChestShop.getBukkitLogger().log(Level.SEVERE, "Error while updating metadata-version from " + previousVersion + " to " + newVersion, e);
} }
} else { } else {
ChestShop.getBukkitLogger().log(Level.WARNING, "Error while updating Item Metadata database! While the plugin will still run it will work less efficiently."); ChestShop.getBukkitLogger().log(Level.WARNING, "Error while updating Item Metadata database! While the plugin will still run it will work less efficiently.");