{"id":"97fb93578503632a","repo":"prisma/prisma","slug":"usage-pnpm-start-proximity-chain-t0-d1-t1","errorCode":null,"errorMessage":"Usage: pnpm start -- proximity-chain <t0> <d1> <t1> [<d2> <t2> ...]","messagePattern":"Usage: pnpm start -- proximity-chain <t0> <d1> <t1> \\[<d2> <t2> \\.\\.\\.\\]","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"examples/paradedb-demo/src/main.ts","lineNumber":19,"sourceCode":"import 'dotenv/config';\nimport { loadAppConfig } from './app-config';\nimport { ormClientBm25TopMatches } from './orm-client/bm25-top-matches';\nimport { db } from './prisma/db';\nimport { bm25CastDemo } from './queries/bm25-cast-demo';\nimport { bm25ChainDemo } from './queries/bm25-chain-demo';\nimport { bm25Fuzzy } from './queries/bm25-fuzzy';\nimport { bm25Match } from './queries/bm25-match';\nimport { bm25ModeTour } from './queries/bm25-mode-tour';\nimport { bm25Proximity } from './queries/bm25-proximity';\nimport { bm25ProximityChain, type ProximityChainStep } from './queries/bm25-proximity-chain';\nimport { bm25TopByScore } from './queries/bm25-top-by-score';\n\nfunction parseProximityChainArgs(args: readonly string[]): {\n  readonly start: string;\n  readonly steps: readonly ProximityChainStep[];\n} {\n  if (args.length < 3 || args.length % 2 !== 1) {\n    throw new Error('Usage: pnpm start -- proximity-chain <t0> <d1> <t1> [<d2> <t2> ...]');\n  }\n  const [start, ...rest] = args;\n  if (start === undefined) {\n    throw new Error('proximity-chain: <t0> is required');\n  }\n  const steps: ProximityChainStep[] = [];\n  for (let i = 0; i < rest.length; i += 2) {\n    const distRaw = rest[i];\n    const term = rest[i + 1];\n    if (distRaw === undefined || term === undefined) {\n      throw new Error(\n        `proximity-chain: trailing distance with no following term at position ${i + 1}`,\n      );\n    }\n    const ordered = distRaw.startsWith('>');\n    const distStr = ordered ? distRaw.slice(1) : distRaw;\n    const distance = Number.parseInt(distStr, 10);\n    if (!Number.isInteger(distance) || distance < 0) {","sourceCodeStart":1,"sourceCodeEnd":37,"githubUrl":"https://github.com/prisma/prisma/blob/1243cdffbec0506c595ac8fd5865fe258c336fa0/examples/paradedb-demo/src/main.ts#L1-L37","documentation":"Thrown by parseProximityChainArgs in the paradedb-demo CLI when the argument count for the proximity-chain subcommand is wrong. It requires an odd count of at least 3 args (t0 d1 t1, optionally more d/t pairs), so any even count or fewer than 3 args triggers the usage error. This is the CLI's structural validation before any term/distance parsing.","triggerScenarios":"Invoking `pnpm start -- proximity-chain ...` with fewer than 3 arguments or an even number of arguments. Examples: `proximity-chain foo`, `proximity-chain foo 1` (2 args), `proximity-chain foo 1 bar 2` (4 args).","commonSituations":"Omitting the trailing term, forgetting a distance, or pasting an incomplete chain. Users often try `proximity-chain term1 term2` expecting adjacency without specifying distances.","solutions":["Provide an odd argument count >= 3: start term, then repeating distance+term pairs, e.g. `proximity-chain t0 1 t1`.","Add the missing term at the end, or remove a dangling distance, so total args are odd.","For longer chains, append pairs: `proximity-chain t0 1 t1 2 t2` (5 args).","Re-read the usage line and count your tokens before retrying."],"exampleFix":"// before\n$ pnpm start -- proximity-chain apples oranges\n// after\n$ pnpm start -- proximity-chain apples 2 oranges","handlingStrategy":"validation","validationCode":"const args = process.argv.slice(2).filter((a) => a !== '--');\nif (args.length < 3 || args.length % 2 !== 1) {\n  console.error('Usage: pnpm start -- proximity-chain <t0> <d1> <t1> [<d2> <t2> ...]');\n  process.exit(1);\n}\n// now safe to call parseProximityChainArgs(args)","typeGuard":"const isProximityArgShape = (a: readonly unknown[]): a is [string, ...string[]] =>\n  a.length >= 3 && a.length % 2 === 1 && a.every((x) => typeof x === 'string');","tryCatchPattern":"try {\n  const { start, steps } = parseProximityChainArgs(args);\n} catch (error) {\n  if (error instanceof Error && error.message.startsWith('Usage:')) {\n    console.error(error.message);\n    process.exit(1);\n  }\n  throw error;\n}","preventionTips":["Pre-check arg count/parity at the CLI boundary so usage prints before any parsing runs.","Use a dedicated arg parser (e.g. commander/yargs) with declared arity to get usage text for free.","Treat the usage message as the contract: keep the README example in sync with it.","Wrap parseProximityChainArgs in a try/catch that re-emits the usage string on any of its known errors."],"tags":["cli","arguments","validation","paradedb","examples","bm25"],"analyzedSha":"1243cdffbec0506c595ac8fd5865fe258c336fa0","analyzedAt":"2026-08-01T19:42:02.087Z","schemaVersion":2}