Add missing NOT NULL constraint violation error codes

This commit is contained in:
Aurora Lahtela 2022-05-24 22:17:56 +03:00
parent 92ed27a097
commit 66ed6cfc5f
2 changed files with 17 additions and 10 deletions

View File

@ -74,6 +74,7 @@ public class DBOpException extends IllegalStateException implements ExceptionWit
break;
// Duplicate key
case 1062:
case 1022:
case 23001:
case 23505:
context.related("Duplicate key")
@ -85,7 +86,6 @@ public class DBOpException extends IllegalStateException implements ExceptionWit
case 531:
case 787:
case 1043:
case 1299:
case 1555:
case 2579:
case 1811:
@ -111,7 +111,8 @@ public class DBOpException extends IllegalStateException implements ExceptionWit
context.related("SQLite file is corrupt.")
.whatToDo("SQLite database is corrupt, restore database.db, .db-shm & .db-wal files from a backup, or repair the database: See https://wordpress.semnaitik.com/repair-sqlite-database/.");
break;
case 13:
case 13: // SQLite
case 1021: // MariaDB
context.related("Disk or temporary directory is full.")
.whatToDo("Disk or temporary directory is full, attempt to clear space in the temporary directory. See https://sqlite.org/rescode.html#full. If you use the Pterodactyl panel, increase the \"tmpfs_size\" config setting. See https://pterodactyl.io/wings/1.0/configuration.html#other-values");
break;
@ -127,11 +128,17 @@ public class DBOpException extends IllegalStateException implements ExceptionWit
break;
case 1267:
case 1366:
case 1115:
context.related("Incorrect character encoding in MySQL")
.whatToDo("Convert your MySQL database and tables to use utf8mb4: https://www.a2hosting.com/kb/developer-corner/mysql/convert-mysql-database-utf-8");
break;
case 1048:
// MySQL
case 1299: // SQLite
case 1048: // MySQL or MariaDB
case 1452:
case 1121:
case 1171:
case 1830:
case 1263:
context.related(CONSTRAINT_VIOLATION)
.whatToDo("Report this error. NOT NULL constraint violation occurred.");
break;

View File

@ -46,11 +46,11 @@ public interface PingQueriesTest extends DatabaseTestPreparer {
default void pingStoreTransactionOutOfOrderDoesNotFailDueToMissingUser() {
DateObj<Integer> saved = RandomData.randomIntDateObject();
int value = saved.getValue();
db().executeTransaction(new PingStoreTransaction(playerUUID, serverUUID(),
db().executeTransaction(new PingStoreTransaction(player2UUID, serverUUID(),
Collections.singletonList(saved)
));
Map<UUID, List<Ping>> expected = Collections.singletonMap(playerUUID, Collections.singletonList(
Map<UUID, List<Ping>> expected = Collections.singletonMap(player2UUID, Collections.singletonList(
new Ping(saved.getDate(), serverUUID(), value, value, value)
));
Map<UUID, List<Ping>> fetched = db().query(PingQueries.fetchAllPingData());
@ -60,14 +60,14 @@ public interface PingQueriesTest extends DatabaseTestPreparer {
@Test
default void pingStoreTransactionOutOfOrderUpdatesUserInformation() {
db().executeTransaction(new PingStoreTransaction(playerUUID, serverUUID(),
db().executeTransaction(new PingStoreTransaction(player2UUID, serverUUID(),
Collections.singletonList(RandomData.randomIntDateObject())
));
long registerDate = RandomData.randomTime();
db().executeTransaction(new PlayerRegisterTransaction(playerUUID, () -> registerDate, TestConstants.PLAYER_ONE_NAME));
db().executeTransaction(new PlayerRegisterTransaction(player2UUID, () -> registerDate, TestConstants.PLAYER_ONE_NAME));
Optional<BaseUser> expected = Optional.of(new BaseUser(playerUUID, TestConstants.PLAYER_ONE_NAME, registerDate, 0));
Optional<BaseUser> result = db().query(BaseUserQueries.fetchBaseUserOfPlayer(playerUUID));
Optional<BaseUser> expected = Optional.of(new BaseUser(player2UUID, TestConstants.PLAYER_ONE_NAME, registerDate, 0));
Optional<BaseUser> result = db().query(BaseUserQueries.fetchBaseUserOfPlayer(player2UUID));
assertEquals(expected, result);
}