usebruno/bruno · error · Error
Unknown statement: "${name}"
Error message
Unknown statement: "${name}" What it means
Thrown by Statements.execute when the requested name is absent from both the prepared-statement map and the statement-definition map. The maps are populated at construction from generated statementDefs, so a missing name means the caller asked for a statement that was never registered — a programming or codegen-sync error, not a data error.
Source
Thrown at packages/bruno-sqlite/src/node/statements.ts:25
export class Statements {
_prepared: Map<string, StatementSync> = new Map();
_defs: Map<string, StatementDef> = new Map();
_onMutation?: OnMutation;
constructor(db: DatabaseSync, onMutation?: OnMutation) {
this._onMutation = onMutation;
for (const def of statementDefs) {
this._defs.set(def.name, def);
this._prepared.set(def.name, db.prepare(def.sql));
}
}
execute(name: string, params: SQLiteParams = {}): unknown {
const stmt = this._prepared.get(name);
const def = this._defs.get(name);
if (stmt === undefined || def === undefined) {
throw new Error(`Unknown statement: "${name}"`);
}
const args = params as Record<string, SupportedValueType>;
switch (def.type) {
case 'exec': {
const result = stmt.run(args);
this._onMutation?.({ name: def.name, tables: def.tables });
return result;
}
case 'one':
return stmt.get(args);
case 'many':
return stmt.all(args);
default:
throw new Error(`unknown definition type: ${def.type}`);
}
}
}
View on GitHub (pinned to 9bdd81c7bd)
Solutions
- Verify the exact name against the generated statementDefs (import { statements } from '../generated/node/statements') — names are case- and underscore-sensitive.
- Re-run the statement codegen so the generated bundle reflects the current SQL definitions.
- If upgrading bruno-sqlite, align the consumer package version so the call sites use names that exist in this version's bundle.
- Type the execute() name parameter as a union of valid names (derived from statementDefs) so the compiler catches typos at build time.
Example fix
// before
const row = statements.execute('getUserbyId', { id }); // case typo
// after
const row = statements.execute('getUserById', { id }); // matches generated def name Defensive patterns
Strategy: type-guard
Validate before calling
import { statements as statementDefs } from '../generated/node/statements';
const VALID_NAMES = new Set(statementDefs.map(d => d.name));
function assertKnownStatement(name) {
if (!VALID_NAMES.has(name)) {
throw new Error(`Unknown statement '${name}'. Valid: ${[...VALID_NAMES].join(', ')}`);
}
}
assertKnownStatement(name);
return statements.execute(name, params); Type guard
import { statements as statementDefs } from '../generated/node/statements';
type StatementName = (typeof statementDefs)[number]['name'];
function isStatementName(name) { return VALID_NAMES.has(name); }
// Narrow before execute:
if (!isStatementName(name)) throw new Error(`Invalid statement name: ${name}`);
statements.execute(name, params); Prevention
- Type execute()'s name parameter as a literal union generated from statementDefs so typos fail at compile time.
- Re-run the statement codegen whenever SQL is added or renamed, before building.
- Keep bruno-sqlite and its consumers version-aligned to avoid name drift.
- Treat 'Unknown statement' as a build/codegen bug, not a runtime data error.
When it happens
Trigger: A caller passes a typo'd or wrong-cased name; the caller uses a name introduced in a newer build of bruno-sqlite while running against an older generated statements bundle; the statements codegen step was skipped so the bundle is incomplete; a refactor renamed a statement but not all call sites.
Common situations: Mismatched versions between a consumer package and bruno-sqlite; forgot to re-run the statement codegen after adding a new SQL statement; copy-paste of a statement name with wrong casing; IDE autocomplete suggesting a name that exists in source but not in the generated bundle.
Related errors
- Migration "${migration.name}" (sequence ${migration.sequence
- Failed to open the database.
- Invalid scope type: ${scopeType}
- Workspace configuration must be an object
- Invalid item: missing type
AI-assisted analysis of usebruno/bruno@9bdd81c7bd (2026-08-13).
Data as JSON: /api/errors/a3d4916ef1391e22.
Report an issue: GitHub.