Open History to see the last commit
1/**
2 * Error text including the `cause` chain. Drizzle wraps the real D1 error
3 * (e.g. `D1_ERROR: ...`) in a DrizzleQueryError whose own message is the
4 * full SQL + params dump — without the chain the actual failure is lost.
5 * Each link is truncated so query/params dumps can't bloat logs past what
6 * Workers Logs stores.
7 */
8export function errorMessage(error: unknown, maxPartLength = 300): string {
9 const parts: Array<string> = []
10 let current: unknown = error
11 while (current !== undefined && current !== null && parts.length < 5) {
12 const text = current instanceof Error ? current.message : String(current)
13 parts.push(
14 text.length > maxPartLength ? `${text.slice(0, maxPartLength)}…` : text,
15 )
16 current = current instanceof Error ? current.cause : undefined
17 }
18 return parts.join(' ← caused by: ')
19}