Repository navigation
fix(db): MySQL index creation silently swallows all errors - #192
Open
MCForgeTitle123 wants to merge 1 commit into
Open
MCForgeTitle123 wants to merge 1 commit into
MCForgeTitle123 wants to merge 1 commit into
Conversation
…e index SchemaSupport.createUniqueIndex swallowed every RuntimeException on MySQL because MySQL lacks CREATE INDEX IF NOT EXISTS. The comment claimed only duplicate-index errors were tolerated, but missing tables, bad columns and connection failures were silently ignored too - leaving the index uncreated with no log, which later allows duplicate rows. Now inspect the SQLException cause chain and only ignore MySQL error 1061 (ER_DUP_KEYNAME); all other failures are rethrown. SQLite is unchanged (it uses IF NOT EXISTS, so any error is genuine).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Bug
SchemaSupport.createUniqueIndexcaught everyRuntimeExceptionon MySQL (which lacksCREATE INDEX IF NOT EXISTS). Although the comment said it only tolerated the "index already exists" error, it also silently swallowed missing-table, bad-column and connection-failure errors. The unique index then never got created, with no log, allowing duplicate rows later.Fix
Walk the exception cause chain and ignore only MySQL error 1061 (
ER_DUP_KEYNAME). Everything else is rethrown. SQLite behaviour is unchanged (IF NOT EXISTSmeans any error is genuine).Verification
SchemaSupportTest(6 cases): duplicate-index ignored; missing table / connection failure / non-SQL runtime exception rethrown; SQLite always rethrows; success path.:fakeplayer-core:test(6/6) +spotlessApplygreen.