{"id":"468e3b8843972195","repo":"drizzle-team/drizzle-orm","slug":"failed-query-query-params-params-468e3b","errorCode":null,"errorMessage":"Failed query: ${query}\nparams: ${params}","messagePattern":"Failed query: (.+?)\nparams: (.+?)","errorType":"exception","errorClass":"DrizzleQueryError","httpStatus":null,"severity":"error","filePath":"drizzle-orm/src/mysql-core/session.ts","lineNumber":79,"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":61,"sourceCodeEnd":97,"githubUrl":"https://github.com/drizzle-team/drizzle-orm/blob/b7862528fd8fc39bc2653a6c18dad7c1f4e68d10/drizzle-orm/src/mysql-core/session.ts#L61-L97","documentation":"Wraps any underlying MySQL driver error in a DrizzleQueryError during query execution. This throw site (line 79) is the catch in MySqlPreparedQuery.queryWithCache for the no-cache path: cache is undefined, is a NoopCache, or query metadata is absent. Provides uniform error shape with SQL + params and the original driver error on .cause.","triggerScenarios":"Any execute/iterator/all/get/values call on a MySQL prepared query that fails at the driver level while no caching layer is active. This is the default execution path for MySQL.","commonSituations":"SQL syntax errors, connection failures, constraint violations, deadlocks, type mismatches between JS params and MySQL columns, or query timeouts against MySQL/PlanetScale.","solutions":["Inspect error.cause for the real MySQL driver error (mysql2 error code/message) and address it.","Log error.query and error.params to reproduce the statement in a MySQL client.","Verify connection config (host, port, credentials, ssl) in drizzle()/drizzleConfig.","For deadlocks/lock timeouts, add retry logic or shorten transactions."],"exampleFix":"// before\nawait db.select().from(users).where(eq(users.email, badEmail));\n\n// after - inspect cause\nimport { DrizzleQueryError } from 'drizzle-orm/errors';\ntry {\n  await db.select().from(users).where(eq(users.email, badEmail));\n} catch (e) {\n  if (e instanceof DrizzleQueryError) {\n    console.error('SQL:', e.query, 'params:', e.params);\n    console.error('driver cause:', e.cause);\n  }\n  throw e;\n}","handlingStrategy":"try-catch","validationCode":"// Pre-validate inputs where possible; driver errors otherwise need try/catch\nif (query == null) throw new Error('query required');","typeGuard":"import { DrizzleQueryError } from '~/errors.ts';\nfunction isDrizzleQueryError(e: unknown): e is DrizzleQueryError {\n  return e instanceof DrizzleQueryError;\n}","tryCatchPattern":"try {\n  await db.select().from(users).where(eq(users.id, id));\n} catch (e) {\n  if (e instanceof DrizzleQueryError) {\n    logger.error({ sql: e.query, params: e.params, cause: e.cause });\n  }\n  throw e;\n}","preventionTips":["Inspect .cause on DrizzleQueryError for the real MySQL driver error/code.","Validate inputs and keep schema in sync to avoid constraint errors.","Configure connection pool and SSL appropriately for your MySQL server.","Add retry for transient errors like ER_LOCK_DEADLOCK."],"tags":["mysql","query-execution","driver-error","database"],"analyzedSha":"b7862528fd8fc39bc2653a6c18dad7c1f4e68d10","analyzedAt":"2026-08-03T18:11:14.318Z","schemaVersion":2}