fix(db): open the move's SQLite source through openDatabase, keep the drop failure as the cause

ESLint refused both: better-sqlite3 is imported only in src/db/connection.ts and its named neighbours, and an error thrown in a catch carries what that catch caught.
This commit is contained in:
Maurice
2026-11-17 14:43:02 +01:00
parent 900f2bfc30
commit 5316362e9e
2 changed files with 10 additions and 6 deletions
@@ -256,15 +256,15 @@ async function copyAll(
* empty before it, so everything in its schema is the move's). When even that
* fails, the error says so, since the database then needs dropping by hand.
*/
async function emptyAgain(db: Kysely<object>, cause: unknown): Promise<void> {
async function emptyAgain(db: Kysely<object>, failure: unknown): Promise<void> {
try {
await run(db, CLEAR_SCHEMA_SQL);
} catch (err) {
throw new Error(
`The move failed (${cause instanceof Error ? cause.message : String(cause)}), and the schema it had created ` +
`The move failed (${failure instanceof Error ? failure.message : String(failure)}), and the schema it had created ` +
`could not be dropped (${err instanceof Error ? err.message : String(err)}). Drop the Postgres database and ` +
'create it again before the next attempt.',
{ cause },
{ cause: err },
);
}
}