drizzle-team/drizzle-orm · error · DrizzleQueryError

Failed query: ${queryString} params: ${params}

Error message

Failed query: ${queryString}
params: ${params}

What it means

DrizzleQueryError thrown in SingleStorePreparedQuery.queryWithCache (session.ts:77) in the no-cache / NoopCache branch. When the underlying driver query rejects, Drizzle wraps the driver error and re-throws with the rendered SQL and bound params for diagnostics. The original error is preserved on `.cause`.

Source

Thrown at drizzle-orm/src/singlestore-core/session.ts:77

		if (cache && cache.strategy() === 'all' && cacheConfig === undefined) {
			this.cacheConfig = { enable: true, autoInvalidate: true };
		}
		if (!this.cacheConfig?.enable) {
			this.cacheConfig = undefined;
		}
	}

	/** @internal */
	protected async queryWithCache<T>(
		queryString: string,
		params: any[],
		query: () => Promise<T>,
	): Promise<T> {
		if (this.cache === undefined || is(this.cache, NoopCache) || this.queryMetadata === undefined) {
			try {
				return await query();
			} catch (e) {
				throw new DrizzleQueryError(queryString, params, e as Error);
			}
		}

		// don't do any mutations, if globally is false
		if (this.cacheConfig && !this.cacheConfig.enable) {
			try {
				return await query();
			} catch (e) {
				throw new DrizzleQueryError(queryString, params, e as Error);
			}
		}

		// For mutate queries, we should query the database, wait for a response, and then perform invalidation
		if (
			(
				this.queryMetadata.type === 'insert' || this.queryMetadata.type === 'update'
				|| this.queryMetadata.type === 'delete'
			) && this.queryMetadata.tables.length > 0

View on GitHub (pinned to b7862528fd)

Solutions

  1. Inspect err.query and err.params (and err.cause) to identify the failing statement and root driver error.
  2. Fix the underlying schema/constraint/data issue revealed by err.cause.
  3. Wrap mutating operations in try/catch on DrizzleQueryError to apply domain-specific recovery or retry.

Example fix

// before
await db.update(users).set({ email }).where(eq(users.id, id));
// after
try {
  await db.update(users).set({ email }).where(eq(users.id, id));
} catch (e) {
  if (e instanceof DrizzleQueryError) console.error(e.query, e.cause);
  throw e;
}
Defensive patterns

Strategy: try-catch

Type guard

import { DrizzleQueryError } from 'drizzle-orm/errors';
function isDrizzleQueryError(e): e is DrizzleQueryError {
  return e instanceof Error && /^Failed query:/.test(e.message);
}

Try / catch

import { DrizzleQueryError } from 'drizzle-orm/errors';
try { await q; } catch (e) {
  if (e instanceof DrizzleQueryError) { logger.error({ query: e.query, params: e.params, cause: e.cause }); }
  throw e;
}

Prevention

When it happens

Trigger: Any executed statement (select/insert/update/delete) fails at the database when caching is disabled or the cache is NoopCache: constraint violations, syntax errors, missing tables, connection drops, deadlocks, etc.

Common situations: Unique-key or foreign-key violations; typos in raw sql fragments; schema drift (table/column renamed in DB but not in code); transient network/connection errors; incorrect bind param types.

Related errors


AI-assisted analysis of drizzle-team/drizzle-orm@b7862528fd (2026-08-03). Data as JSON: /data/errors/ec37fb1812fa343f.json. Report an issue: GitHub.