Skip to content

fix(db): MySQL index creation silently swallows all errors - #192

Open
MCForgeTitle123 wants to merge 1 commit into
EndlessPixel-Studio:masterfrom
MCForgeTitle123:fix/schema-index-error
Open

MCForgeTitle123 wants to merge 1 commit into
EndlessPixel-Studio:masterfrom
MCForgeTitle123:fix/schema-index-error

Conversation

@MCForgeTitle123

Copy link
Copy Markdown
Contributor

Bug

SchemaSupport.createUniqueIndex caught every RuntimeException on MySQL (which lacks CREATE 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 EXISTS means any error is genuine).

Verification

  • Added 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) + spotlessApply green.

…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).
@github-actions github-actions Bot added the core 核心模块 fakeplayer-core label Dec 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

core 核心模块 fakeplayer-core

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant