{"record":{"id":"d2724a6545b182fa","repo":"paperclipai/paperclip","slug":"sql-placeholder-match-1-has-no-matching-param","errorCode":null,"errorMessage":"SQL placeholder $${match[1]} has no matching parameter","messagePattern":"SQL placeholder \\$(.+?) has no matching parameter","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"server/src/services/plugin-database.ts","lineNumber":314,"sourceCode":"  for (const ref of refs) {\n    if (ref.schema !== namespace) {\n      throw new Error(\"ctx.db.execute cannot reference public or other non-plugin schemas\");\n    }\n  }\n}\n\nfunction bindSql(statement: string, params: readonly unknown[] = []): SQL {\n  // Safe only after callers run the plugin SQL validators above.\n  if (params.length === 0) return sql.raw(statement);\n  const chunks: SQL[] = [];\n  let cursor = 0;\n  const placeholderPattern = /\\$(\\d+)/g;\n  const seen = new Set<number>();\n\n  for (const match of statement.matchAll(placeholderPattern)) {\n    const index = Number(match[1]);\n    if (!Number.isInteger(index) || index < 1 || index > params.length) {\n      throw new Error(`SQL placeholder $${match[1]} has no matching parameter`);\n    }\n    chunks.push(sql.raw(statement.slice(cursor, match.index)));\n    chunks.push(sql`${params[index - 1]}`);\n    seen.add(index);\n    cursor = match.index! + match[0].length;\n  }\n  chunks.push(sql.raw(statement.slice(cursor)));\n  if (seen.size !== params.length) {\n    throw new Error(\"Every ctx.db parameter must be referenced by a $n placeholder\");\n  }\n  return sql.join(chunks, sql.raw(\"\"));\n}\n\nasync function listSqlMigrationFiles(migrationsDir: string): Promise<string[]> {\n  const entries = await readdir(migrationsDir, { withFileTypes: true });\n  return entries\n    .filter((entry) => entry.isFile() && entry.name.endsWith(\".sql\"))\n    .map((entry) => entry.name)","sourceCodeStart":296,"sourceCodeEnd":332,"githubUrl":"https://github.com/paperclipai/paperclip/blob/120ae5428fa29bee300bcf806491cd4d965fbb7c/server/src/services/plugin-database.ts#L296-L332","documentation":"Parameter-binding guard in bindSql: the statement contains a $n placeholder whose index is not an integer in the 1..params.length range, so the placeholder refers to a parameter the caller never supplied. The mismatched placeholder/params pair is at fault.","triggerScenarios":"Thrown at server/src/services/plugin-database.ts:314 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Add a parameter for every $n placeholder in the SQL, or remove the unmatched placeholder."],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"120ae5428fa29bee300bcf806491cd4d965fbb7c","analyzedAt":"2026-08-18T22:49:45.177Z","contentChangedAt":"2026-08-18T22:49:45.177Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}