{"id":"2f5345a76500b556","repo":"drizzle-team/drizzle-orm","slug":"failed-query-querystring-params-params-2f5345","errorCode":null,"errorMessage":"Failed query: ${queryString}\nparams: ${params}","messagePattern":"Failed query: (.+?)\nparams: (.+?)","errorType":"exception","errorClass":"DrizzleQueryError","httpStatus":null,"severity":"error","filePath":"drizzle-orm/src/sqlite-core/session.ts","lineNumber":80,"sourceCode":"\t\tif (cache && cache.strategy() === 'all' && cacheConfig === undefined) {\n\t\t\tthis.cacheConfig = { enable: true, autoInvalidate: true };\n\t\t}\n\t\tif (!this.cacheConfig?.enable) {\n\t\t\tthis.cacheConfig = undefined;\n\t\t}\n\t}\n\n\t/** @internal */\n\tprotected async queryWithCache<T>(\n\t\tqueryString: string,\n\t\tparams: any[],\n\t\tquery: () => Promise<T>,\n\t): Promise<T> {\n\t\tif (this.cache === undefined || is(this.cache, NoopCache) || this.queryMetadata === undefined) {\n\t\t\ttry {\n\t\t\t\treturn await query();\n\t\t\t} catch (e) {\n\t\t\t\tthrow new DrizzleQueryError(queryString, params, e as Error);\n\t\t\t}\n\t\t}\n\n\t\t// don't do any mutations, if globally is false\n\t\tif (this.cacheConfig && !this.cacheConfig.enable) {\n\t\t\ttry {\n\t\t\t\treturn await query();\n\t\t\t} catch (e) {\n\t\t\t\tthrow new DrizzleQueryError(queryString, params, e as Error);\n\t\t\t}\n\t\t}\n\n\t\t// For mutate queries, we should query the database, wait for a response, and then perform invalidation\n\t\tif (\n\t\t\t(\n\t\t\t\tthis.queryMetadata.type === 'insert' || this.queryMetadata.type === 'update'\n\t\t\t\t|| this.queryMetadata.type === 'delete'\n\t\t\t) && this.queryMetadata.tables.length > 0","sourceCodeStart":62,"sourceCodeEnd":98,"githubUrl":"https://github.com/drizzle-team/drizzle-orm/blob/b7862528fd8fc39bc2653a6c18dad7c1f4e68d10/drizzle-orm/src/sqlite-core/session.ts#L62-L98","documentation":"A DrizzleQueryError thrown from SQLiteSession.queryWithCache (session.ts:80) on the no-cache code path (cache undefined, a NoopCache, or no queryMetadata). When the underlying driver query rejects, drizzle wraps it so the thrown error carries the generated SQL and bound params. The original driver error is preserved on .cause.","triggerScenarios":"Any SELECT/INSERT/UPDATE/DELETE executed through a session that has no cache configured, where the database itself returns an error: constraint violation, syntax error, missing table, busy/locked, type mismatch, etc. The wrapper fires because the session has no cache to consult.","commonSituations":"Unique-constraint violations on insert; NOT NULL violations; querying a non-existent table after a schema change; SQLite SQLITE_BUSY under concurrency; type affinity mismatches; malformed SQL from raw sql`` fragments.","solutions":["Inspect error.cause for the native SQLite error code (e.g. SQLITE_CONSTRAINT) to pinpoint the root cause.","Read the embedded queryString/params in the DrizzleQueryError to reproduce the statement.","Fix the underlying schema/data/concurrency issue (add missing table, dedupe inserts, wrap in a transaction/retry on SQLITE_BUSY)."],"exampleFix":"// before\nawait db.insert(users).values({ id: 1 });\n// duplicate id -> DrizzleQueryError: Failed query: insert into ...\n\n// after — handle the constraint\ntry {\n  await db.insert(users).values({ id: 1 });\n} catch (e) {\n  if (e instanceof DrizzleQueryError && /UNIQUE constraint/i.test(e.cause?.message ?? '')) {\n    // duplicate — ignore or upsert\n  } else throw e;\n}","handlingStrategy":"try-catch","validationCode":null,"typeGuard":"import { DrizzleQueryError } from 'drizzle-orm';\nconst isDrizzleQueryError = (e): e is DrizzleQueryError => e instanceof DrizzleQueryError;","tryCatchPattern":"try {\n  await db.insert(users).values(row);\n} catch (e) {\n  if (e instanceof DrizzleQueryError) {\n    // e.query, e.params, e.cause (native SQLite error)\n    if (/UNIQUE constraint/i.test(e.cause?.message ?? '')) {\n      // handle duplicate\n    } else {\n      logger.error({ sql: e.query, params: e.params, cause: e.cause?.message });\n      throw e;\n    }\n  } else throw e;\n}","preventionTips":["Validate data (uniqueness, NOT NULL, FK existence) before writes to avoid driver errors.","Wrap multi-step writes in transactions so a failure rolls back atomically.","Always inspect .cause for the native SQLite error code rather than parsing the wrapper message."],"tags":["runtime","session","sqlite","driver-error","wrapper"],"analyzedSha":"b7862528fd8fc39bc2653a6c18dad7c1f4e68d10","analyzedAt":"2026-08-03T18:11:14.318Z","schemaVersion":2}