{"id":"dd99d6f3b010d83e","repo":"drizzle-team/drizzle-orm","slug":"it-code-it-message","errorCode":null,"errorMessage":"${it.code}: ${it.message}","messagePattern":"\\$\\{it\\.code\\}: \\$\\{it\\.message\\}","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"drizzle-kit/src/cli/connections.ts","lineNumber":1054,"sourceCode":"\t\t\t) => {\n\t\t\t\tconst res = await fetch(\n\t\t\t\t\t`https://api.cloudflare.com/client/v4/accounts/${credentials.accountId}/d1/database/${credentials.databaseId}/${\n\t\t\t\t\t\tmethod === 'values' ? 'raw' : 'query'\n\t\t\t\t\t}`,\n\t\t\t\t\t{\n\t\t\t\t\t\tmethod: 'POST',\n\t\t\t\t\t\tbody: JSON.stringify({ sql, params }),\n\t\t\t\t\t\theaders: {\n\t\t\t\t\t\t\t'Content-Type': 'application/json',\n\t\t\t\t\t\t\tAuthorization: `Bearer ${credentials.token}`,\n\t\t\t\t\t\t},\n\t\t\t\t\t},\n\t\t\t\t);\n\n\t\t\t\tconst data = (await res.json()) as D1Response;\n\n\t\t\t\tif (!data.success) {\n\t\t\t\t\tthrow new Error(\n\t\t\t\t\t\tdata.errors.map((it) => `${it.code}: ${it.message}`).join('\\n'),\n\t\t\t\t\t);\n\t\t\t\t}\n\n\t\t\t\tconst result = data.result[0].results;\n\t\t\t\tconst rows = Array.isArray(result) ? result : result.rows;\n\n\t\t\t\treturn {\n\t\t\t\t\trows,\n\t\t\t\t};\n\t\t\t};\n\n\t\t\tconst remoteBatchCallback = async (\n\t\t\t\tqueries: {\n\t\t\t\t\tsql: string;\n\t\t\t\t}[],\n\t\t\t) => {\n\t\t\t\tconst sql = queries.map((q) => q.sql).join('; ');","sourceCodeStart":1036,"sourceCodeEnd":1072,"githubUrl":"https://github.com/drizzle-team/drizzle-orm/blob/b7862528fd8fc39bc2653a6c18dad7c1f4e68d10/drizzle-kit/src/cli/connections.ts#L1036-L1072","documentation":"Surfaced by the Cloudflare D1 HTTP driver in drizzle-kit. After POSTing a single SQL statement to the D1 REST endpoint, the SDK inspects `data.success`; when Cloudflare returns `success: false` it concatenates each `{code, message}` error pair into a single thrown Error. This is the remote API's error payload re-thrown locally, so the originating code is Cloudflare's (auth, SQL syntax, database state) rather than drizzle's.","triggerScenarios":"Configuring `driver: 'd1-http'` with `accountId`, `databaseId`, and `token`, then executing any query through Studio or migrate whose SQL is rejected by D1 (syntax error, missing table, insufficient token scopes, wrong/invalid databaseId).","commonSituations":"Expired or wrong-scoped Cloudflare API token (code 10000/8000011), mistyped `databaseId`/`accountId`, schema drift (querying a table not yet migrated), or a SQL syntax error generated by a stale drizzle schema.","solutions":["Inspect the concatenated `<code>: <message>` text; Cloudflare error codes (e.g. 8000011 invalid token, 7000/7003 SQL errors) point at the root cause.","Verify the token has the `D1 Edit` / `Account D1 write` permission and is not expired.","Confirm `accountId` and `databaseId` in `drizzle.config.ts` match a database listed via `wrangler d1 list`.","If it is a SQL/schema error, run `drizzle-kit migrate` again or fix the offending statement."],"exampleFix":"// before\ntoken: process.env.CF_API_TOKEN // wrong-scoped token\n// after - regenerate token granting D1 Edit on the account\ntoken: process.env.CF_D1_TOKEN","handlingStrategy":"try-catch","validationCode":"// Validate D1 credentials before first query\nfunction assertD1Creds(c: { accountId: string; databaseId: string; token: string }) {\n  if (!c.accountId || !c.databaseId || !c.token) throw new Error('Incomplete D1 credentials');\n}","typeGuard":"function isD1ErrorResponse(d: any): d is { success: false; errors: { code: number; message: string }[] } {\n  return d && d.success === false && Array.isArray(d.errors);\n}","tryCatchPattern":"try {\n  const res = await studioDb.execute(sql`...`);\n} catch (e) {\n  const msg = (e as Error).message;\n  // msg is `<code>: <message>` joined by newlines; parse the first code\n  const code = parseInt(msg.split(':')[0]!, 10);\n  if (code === 8000011) console.error('Token invalid/expired - regenerate it');\n  throw e;\n}","preventionTips":["Grant the Cloudflare token `D1 Edit` scope on the target account.","Cross-check accountId/databaseId with `wrangler d1 list`.","Wrap Studio/migrate calls and parse the numeric code to classify failures."],"tags":["drizzle-kit","cloudflare-d1","http-driver","api-errors"],"analyzedSha":"b7862528fd8fc39bc2653a6c18dad7c1f4e68d10","analyzedAt":"2026-08-03T18:11:14.318Z","schemaVersion":2}