mirror of
https://github.com/saltbo/zpan.git
synced 2026-08-29 00:01:42 +08:00
d2f3a34f05
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>
24 lines
880 B
TypeScript
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')
|
|
})
|
|
})
|