{"record":{"id":"a3d4916ef1391e22","repo":"usebruno/bruno","slug":"unknown-statement-name","errorCode":null,"errorMessage":"Unknown statement: \"${name}\"","messagePattern":"Unknown statement: \"(.+?)\"","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/bruno-sqlite/src/node/statements.ts","lineNumber":25,"sourceCode":"\nexport class Statements {\n  _prepared: Map<string, StatementSync> = new Map();\n  _defs: Map<string, StatementDef> = new Map();\n  _onMutation?: OnMutation;\n\n  constructor(db: DatabaseSync, onMutation?: OnMutation) {\n    this._onMutation = onMutation;\n    for (const def of statementDefs) {\n      this._defs.set(def.name, def);\n      this._prepared.set(def.name, db.prepare(def.sql));\n    }\n  }\n\n  execute(name: string, params: SQLiteParams = {}): unknown {\n    const stmt = this._prepared.get(name);\n    const def = this._defs.get(name);\n    if (stmt === undefined || def === undefined) {\n      throw new Error(`Unknown statement: \"${name}\"`);\n    }\n    const args = params as Record<string, SupportedValueType>;\n    switch (def.type) {\n      case 'exec': {\n        const result = stmt.run(args);\n        this._onMutation?.({ name: def.name, tables: def.tables });\n        return result;\n      }\n      case 'one':\n        return stmt.get(args);\n      case 'many':\n        return stmt.all(args);\n      default:\n        throw new Error(`unknown definition type: ${def.type}`);\n    }\n  }\n}\n","sourceCodeStart":7,"sourceCodeEnd":43,"githubUrl":"https://github.com/usebruno/bruno/blob/9bdd81c7bdc57006e5f5ebffb79321a8d979f712/packages/bruno-sqlite/src/node/statements.ts#L7-L43","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\nconst row = statements.execute('getUserbyId', { id }); // case typo\n\n// after\nconst row = statements.execute('getUserById', { id }); // matches generated def name","handlingStrategy":"type-guard","validationCode":"import { statements as statementDefs } from '../generated/node/statements';\nconst VALID_NAMES = new Set(statementDefs.map(d => d.name));\nfunction assertKnownStatement(name) {\n  if (!VALID_NAMES.has(name)) {\n    throw new Error(`Unknown statement '${name}'. Valid: ${[...VALID_NAMES].join(', ')}`);\n  }\n}\nassertKnownStatement(name);\nreturn statements.execute(name, params);","typeGuard":"import { statements as statementDefs } from '../generated/node/statements';\ntype StatementName = (typeof statementDefs)[number]['name'];\nfunction isStatementName(name) { return VALID_NAMES.has(name); }\n// Narrow before execute:\nif (!isStatementName(name)) throw new Error(`Invalid statement name: ${name}`);\nstatements.execute(name, params);","tryCatchPattern":null,"preventionTips":["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."],"tags":["database","sqlite","programming-error","codegen","typescript"],"backgroundTag":null,"analyzedSha":"9bdd81c7bdc57006e5f5ebffb79321a8d979f712","analyzedAt":"2026-08-13T04:09:25.751Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}