2FA setup required: the missing-column log reads the error's cause chain
R3-1: the SQL adapters throw "Failed query: …" and put the database's own words
("column … does not exist", "no such column") in the error's cause, so the loud
start-up line never appeared on a real Postgres or SQLite. The reason is now
built from the whole cause chain; other failures (ECONNREFUSED, a locked
database) still only warn. Tested with wrapped errors and against the real
adapter with the column dropped.
Docs and the doctor's fix text name how the migration is applied
(deployment.md 4.3) wherever they said only "before the site serves".
Co-Authored-By: Claude Fable 5.2 <[email protected]>
This commit is contained in:
co-authored by
Claude Fable 5.2
parent
01e3813723
commit
b52193ae47
@@ -194,7 +194,9 @@ export async function backfillSetupFrom(payload: BasePayload, collection: string
|
||||
}
|
||||
return totalDocs
|
||||
} catch (err) {
|
||||
const reason = err instanceof Error ? err.message : String(err)
|
||||
// The whole chain: Drizzle's own message is "Failed query: …", and what the database said
|
||||
// ("column … does not exist", "no such column") is in `cause`.
|
||||
const reason = errorChain(err)
|
||||
// On Postgres / SQLite without the migration the column is missing — and then it is not only this step
|
||||
// that fails: every query on the collection selects the column, so EVERY login answers 500 until it exists.
|
||||
// Only the missing column gets this message — a database that cannot be reached is another problem.
|
||||
@@ -212,6 +214,19 @@ export async function backfillSetupFrom(payload: BasePayload, collection: string
|
||||
}
|
||||
}
|
||||
|
||||
/** The messages of an error and of everything in its `cause` chain, outermost first. */
|
||||
export function errorChain(err: unknown): string {
|
||||
const parts: string[] = []
|
||||
const seen = new Set<unknown>()
|
||||
for (let current: unknown = err; current !== undefined && current !== null && !seen.has(current) && parts.length < 6; current = (current as { cause?: unknown }).cause) {
|
||||
seen.add(current)
|
||||
const message = current instanceof Error || typeof (current as { message?: unknown }).message === 'string' ? String((current as { message: unknown }).message) : typeof current === 'string' ? current : ''
|
||||
if (message && !parts.includes(message)) {parts.push(message)}
|
||||
if (typeof current !== 'object') {break}
|
||||
}
|
||||
return parts.join(' — ') || String(err)
|
||||
}
|
||||
|
||||
export type TwoFactorResetOptions = {
|
||||
/**
|
||||
* Who may reset another account's TOTP. Default: a staff admin whose session has **entered its
|
||||
|
||||
Reference in New Issue
Block a user