{"record":{"id":"0cfbe86c8201e95a","repo":"run-llama/liteparse","slug":"invalid-header-value-expected-name-value","errorCode":null,"errorMessage":"invalid header '${value}', expected 'Name: Value'","messagePattern":"invalid header '(.+?)', expected 'Name: Value'","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/node/src/cli.ts","lineNumber":42,"sourceCode":"    chunks.push(chunk as Buffer);\n  }\n  const bytes = Buffer.concat(chunks);\n  if (bytes.length === 0) {\n    throw new Error(\n      \"no data on stdin (input `-` expects a document piped in, e.g. `curl … | liteparse parse -`)\",\n    );\n  }\n  return bytes;\n}\n\n/** Collect repeated `--ocr-server-header \"Name: Value\"` flags into an object. */\nfunction collectHeader(\n  value: string,\n  previous: Record<string, string> = {},\n): Record<string, string> {\n  const idx = value.indexOf(\":\");\n  if (idx === -1) {\n    throw new Error(`invalid header '${value}', expected 'Name: Value'`);\n  }\n  const name = value.slice(0, idx).trim();\n  if (name === \"\") {\n    throw new Error(`invalid header '${value}', empty header name`);\n  }\n  previous[name] = value.slice(idx + 1).trim();\n  return previous;\n}\n\nprogram\n  .command(\"parse\")\n  .description(\"Parse a document and extract text\")\n  .argument(\"<file>\", \"Path to the document file\")\n  .option(\"-o, --output <file>\", \"Output file path\")\n  .option(\"--format <format>\", 'Output format: json|text|markdown (default: \"text\")')\n  .option(\n    \"--image-mode <mode>\",\n    \"How to surface raster images in markdown: off|placeholder|embed (default: placeholder)\",","sourceCodeStart":24,"sourceCodeEnd":60,"githubUrl":"https://github.com/run-llama/liteparse/blob/22d2dd8cd7f7b9320102b57ddaf0e663ff7d15a8/packages/node/src/cli.ts#L24-L60","documentation":"The `--header` CLI option is parsed by collectHeader, which requires the value to contain a `:` separating name and value. A header argument without any colon cannot be split into a name/value pair, so the CLI rejects it with this message showing the expected `Name: Value` shape. This is used when passing headers to a remote OCR HTTP server.","triggerScenarios":"Passing `--header Authorization` (no colon) or a value where the colon was eaten by the shell, e.g. an unquoted or mistyped argument to the `--header` repeatable option in `packages/node/src/cli.ts`.","commonSituations":"Copy-pasting curl-style header examples into the CLI flag; forgetting quotes around headers containing spaces so the shell splits them; typos like `--header=Authorization-Bearer xyz`.","solutions":["Include a colon in the value: `--header \"Authorization: Bearer <token>\"`.","Quote the whole header argument so the shell does not split on spaces.","Check `liteparse parse --help` for the exact `--header` syntax expected by collectHeader."],"exampleFix":"// before\nliteparse parse doc.pdf --header Authorization Bearer tok\n// after\nliteparse parse doc.pdf --header \"Authorization: Bearer tok\"","handlingStrategy":"validation","validationCode":"function isValidHeader(h) {\n  const i = h.indexOf(':');\n  return i > 0 && h.slice(0, i).trim() !== '';\n}\n// before invoking CLI:\nif (!headers.every(isValidHeader)) throw new Error('headers must be Name: Value');","typeGuard":"const isHeaderArg = (v) => typeof v === 'string' && /^[^:\\s][^:]*:/.test(v);","tryCatchPattern":"try {\n  await program.parseAsync(process.argv);\n} catch (e) {\n  if (e.message.startsWith('invalid header') && !e.message.includes('empty header name')) {\n    console.error(`Bad --header value. Use: --header \"Name: Value\" (${e.message})`);\n    process.exit(2);\n  }\n  throw e;\n}","preventionTips":["Always quote header arguments containing spaces or colons.","Lint scripts for --header usage with a regex requiring Name: Value.","Build headers programmatically from {name, value} pairs and serialize them yourself."],"tags":["cli","headers","argument-format"],"backgroundTag":"invalid-argument-format","analyzedSha":"22d2dd8cd7f7b9320102b57ddaf0e663ff7d15a8","analyzedAt":"2026-09-08T06:09:49.009Z","contentChangedAt":"2026-09-08T06:09:49.009Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}