Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Founding a Civ or town with a name that already exists throws an unreadable exception in game. #46

Open
ataranlen opened this issue Aug 1, 2016 · 7 comments
Labels

Comments

@ataranlen
Copy link
Owner

Just need to handle this error condition and send a reasonable message back to the user.

[06:36:53] [Server thread/WARN]: com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException: Duplicate entry 'Mirendar' for key 'name'
[06:36:53] [Server thread/WARN]:    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
[06:36:53] [Server thread/WARN]:    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
[06:36:53] [Server thread/WARN]:    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
[06:36:53] [Server thread/WARN]:    at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
[06:36:53] [Server thread/WARN]:    at com.mysql.jdbc.Util.handleNewInstance(Util.java:407)
[06:36:53] [Server thread/WARN]:    at com.mysql.jdbc.Util.getInstance(Util.java:382)
[06:36:53] [Server thread/WARN]:    at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1039)
[06:36:53] [Server thread/WARN]:    at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3593)
[06:36:53] [Server thread/WARN]:    at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3525)
[06:36:53] [Server thread/WARN]:    at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1986)
[06:36:53] [Server thread/WARN]:    at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2140)
[06:36:53] [Server thread/WARN]:    at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2626)
[06:36:53] [Server thread/WARN]:    at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:2111)
[06:36:53] [Server thread/WARN]:    at com.mysql.jdbc.PreparedStatement.execute(PreparedStatement.java:1362)
[06:36:53] [Server thread/WARN]:    at com.jolbox.bonecp.PreparedStatementHandle.execute(PreparedStatementHandle.java:140)
[06:36:53] [Server thread/WARN]:    at com.avrgaming.civcraft.database.SQL.insertNow(SQL.java:510)
[06:36:53] [Server thread/WARN]:    at com.avrgaming.civcraft.database.SQL.updateNamedObject(SQL.java:388)
[06:36:53] [Server thread/WARN]:    at com.avrgaming.civcraft.object.Town.saveNow(Town.java:345)
[06:36:53] [Server thread/WARN]:    at com.avrgaming.civcraft.object.Town.newTown(Town.java:939)
[06:36:53] [Server thread/WARN]:    at com.avrgaming.civcraft.object.Civilization.newCiv(Civilization.java:588)
[06:36:53] [Server thread/WARN]:    at com.avrgaming.civcraft.threading.tasks.FoundCivSync.run(FoundCivSync.java:49)
[06:36:53] [Server thread/WARN]:    at org.bukkit.craftbukkit.v1_8_R3.scheduler.CraftTask.run(CraftTask.java:71)
[06:36:53] [Server thread/WARN]:    at org.bukkit.craftbukkit.v1_8_R3.scheduler.CraftScheduler.mainThreadHeartbeat(CraftScheduler.java:350)
[06:36:53] [Server thread/WARN]:    at net.minecraft.server.v1_8_R3.MinecraftServer.B(MinecraftServer.java:723)
[06:36:53] [Server thread/WARN]:    at net.minecraft.server.v1_8_R3.DedicatedServer.B(DedicatedServer.java:374)
[06:36:53] [Server thread/WARN]:    at net.minecraft.server.v1_8_R3.MinecraftServer.A(MinecraftServer.java:654)
[06:36:53] [Server thread/WARN]:    at net.minecraft.server.v1_8_R3.MinecraftServer.run(MinecraftServer.java:557)
[06:36:53] [Server thread/WARN]:    at java.lang.Thread.run(Thread.java:745)
[06:36:53] [Server thread/WARN]: com.avrgaming.civcraft.exception.CivException: Internal Database Exception, Contact an Admin
[06:36:53] [Server thread/WARN]:    at com.avrgaming.civcraft.object.Town.newTown(Town.java:1019)
[06:36:53] [Server thread/WARN]:    at com.avrgaming.civcraft.object.Civilization.newCiv(Civilization.java:588)
[06:36:53] [Server thread/WARN]:    at com.avrgaming.civcraft.threading.tasks.FoundCivSync.run(FoundCivSync.java:49)
[06:36:53] [Server thread/WARN]:    at org.bukkit.craftbukkit.v1_8_R3.scheduler.CraftTask.run(CraftTask.java:71)
[06:36:53] [Server thread/WARN]:    at org.bukkit.craftbukkit.v1_8_R3.scheduler.CraftScheduler.mainThreadHeartbeat(CraftScheduler.java:350)
[06:36:53] [Server thread/WARN]:    at net.minecraft.server.v1_8_R3.MinecraftServer.B(MinecraftServer.java:723)
[06:36:53] [Server thread/WARN]:    at net.minecraft.server.v1_8_R3.DedicatedServer.B(DedicatedServer.java:374)
[06:36:53] [Server thread/WARN]:    at net.minecraft.server.v1_8_R3.MinecraftServer.A(MinecraftServer.java:654)
[06:36:53] [Server thread/WARN]:    at net.minecraft.server.v1_8_R3.MinecraftServer.run(MinecraftServer.java:557)
[06:36:53] [Server thread/WARN]:    at java.lang.Thread.run(Thread.java:745)
@ataranlen ataranlen changed the title Founding a Civ with a capital name that already exists throws an unreadable exception Founding a Civ with a capital name that already exists throws an unreadable exception in game. Aug 1, 2016
@ataranlen
Copy link
Owner Author

@ataranlen ataranlen added the bug label Aug 1, 2016
@ghost
Copy link

ghost commented Aug 2, 2016

Hey,when im trying add new structure or tech or wonder i have that problem: https://gyazo.com/31dee75a9ead018fff144433eb8a89c5
And when im creating civ data error,dbg buildspawn work.
Help please =)

@ataranlen
Copy link
Owner Author

@TheLegion1337 that looks like a different error. Looks like a YAML issue. Open a new ticket and attach your yml files.

@ataranlen
Copy link
Owner Author

Some additional information: Disconnecting when in the process of founding a town or civ will break the process.

@ataranlen ataranlen changed the title Founding a Civ with a capital name that already exists throws an unreadable exception in game. Founding a Civ or town with a name that already exists throws an unreadable exception in game. Nov 22, 2016
@TheLegionCrazy
Copy link

Maybe?

try {
create sth...
} catch (MySQLIntegrityConstraintViolationException e) {
    if (e.getMessage().contains("Duplicate entry")) 
        throw new CivException("name that already exists");
}

@ataranlen
Copy link
Owner Author

I think the root cause is deeper than just using the same name, as we already have checks in place for duplicate names.

Civilization existCiv = CivGlobal.getCiv(name);
if (existCiv != null) {
	throw new CivException(CivSettings.localize.localizedString("var_civ_found_civExists",name));
}
		
Town existTown = CivGlobal.getTown(capitolName);
if (existTown != null) {
	throw new CivException(CivSettings.localize.localizedString("var_civ_found_townExists",capitolName));
}

@TheLegionCrazy
Copy link

we must check defeated civs too #188

YourCoal added a commit that referenced this issue May 19, 2019
sql exception fix (while creating new civ) [#46 fix]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants