Files
zpan/server/lib/errors.test.ts
T
saltbo d2f3a34f05 fix(server): log underlying cause chain for failed D1 queries
Drizzle wraps the real D1 error in DrizzleQueryError.cause; both the access
log and the origin-detect catch only logged .message, surfacing just
"Failed query: <sql>" with no reason. Add formatError() to flatten the cause
chain and use it at both sites so D1 failures are diagnosable.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-10 00:42:50 -04:00

24 lines
880 B
TypeScript

import { describe, expect, it } from 'vitest'
import { formatError } from './errors'
describe('formatError', () => {
it('returns the message for a plain error', () => {
expect(formatError(new Error('boom'))).toBe('boom')
})
it('flattens the cause chain (drizzle wraps the real D1 error in cause)', () => {
const d1 = new Error('D1_ERROR: Network connection lost')
const wrapped = new Error('Failed query: update "download_tasks" ...', { cause: d1 })
expect(formatError(wrapped)).toBe('Failed query: update "download_tasks" ... <- D1_ERROR: Network connection lost')
})
it('appends a non-Error cause', () => {
const err = new Error('outer', { cause: 'inner string' })
expect(formatError(err)).toBe('outer <- inner string')
})
it('stringifies a non-Error value', () => {
expect(formatError('plain string')).toBe('plain string')
})
})