{"record":{"id":"da5fa350c7dd249d","repo":"tobi/qmd","slug":"line-line-number-starts-with-expand-but-query","errorCode":null,"errorMessage":"Line ${line.number} starts with expand:, but query documents cannot mix expand with typed lines. Submit a single expand query instead.","messagePattern":"Line (.+?) starts with expand:, but query documents cannot mix expand with typed lines\\. Submit a single expand query instead\\.","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/cli/qmd.ts","lineNumber":2741,"sourceCode":"function parseStructuredQuery(query: string): ParsedStructuredQuery | null {\n  const rawLines = query.split('\\n').map((line, idx) => ({\n    raw: line,\n    trimmed: line.trim(),\n    number: idx + 1,\n  })).filter(line => line.trimmed.length > 0);\n\n  if (rawLines.length === 0) return null;\n\n  const prefixRe = /^(lex|vec|hyde):\\s*/i;\n  const expandRe = /^expand:\\s*/i;\n  const intentRe = /^intent:\\s*/i;\n  const typed: ExpandedQuery[] = [];\n  let intent: string | undefined;\n\n  for (const line of rawLines) {\n    if (expandRe.test(line.trimmed)) {\n      if (rawLines.length > 1) {\n        throw new Error(`Line ${line.number} starts with expand:, but query documents cannot mix expand with typed lines. Submit a single expand query instead.`);\n      }\n      const text = line.trimmed.replace(expandRe, '').trim();\n      if (!text) {\n        throw new Error('expand: query must include text.');\n      }\n      return null; // treat as standalone expand query\n    }\n\n    // Parse intent: lines\n    if (intentRe.test(line.trimmed)) {\n      if (intent !== undefined) {\n        throw new Error(`Line ${line.number}: only one intent: line is allowed per query document.`);\n      }\n      const text = line.trimmed.replace(intentRe, '').trim();\n      if (!text) {\n        throw new Error(`Line ${line.number}: intent: must include text.`);\n      }\n      intent = text;","sourceCodeStart":2723,"sourceCodeEnd":2759,"githubUrl":"https://github.com/tobi/qmd/blob/dbfd0b4736aeaf761d1a16ca8e424f071df8feb9/src/cli/qmd.ts#L2723-L2759","documentation":"Thrown by the query-document parser in the CLI when a line starts with 'expand:' but the document has more than one line. expand: queries are standalone: they cannot be mixed with lex:/vec:/hyde:/intent: lines in one document.","triggerScenarios":"Piping or typing a query document like 'expand: machine setup\\nlex: install' to `qmd query`.","commonSituations":"Graduating a typed query to expansion and forgetting to delete the other lines; scripts concatenating query lines.","solutions":["Delete the other lines and submit just the single expand: line","Or drop the expand: line and keep the typed lex:/vec:/hyde: lines"],"exampleFix":"# before\nprintf 'expand: machine setup\\nlex: install' | qmd query\n# after\nprintf 'expand: machine setup' | qmd query","handlingStrategy":"validation","validationCode":"const lines = doc.split('\\n').filter(l => l.trim());\nif (/^\\s*expand:/i.test(doc) && lines.length > 1) throw new Error('expand: must be the only line');","typeGuard":"const isStandaloneExpand = (doc: string) => /^\\s*expand:/i.test(doc) && doc.split('\\n').filter(l => l.trim()).length === 1;","tryCatchPattern":null,"preventionTips":["Treat expand: as a one-line query mode; never concatenate it with typed lines"],"tags":["query","cli","query-syntax"],"backgroundTag":"query-syntax-validation-failed","analyzedSha":"dbfd0b4736aeaf761d1a16ca8e424f071df8feb9","analyzedAt":"2026-08-28T18:07:46.628Z","schemaVersion":2},"datasetVersion":"2026-08-28T21:17:43.275Z"}