{"record":{"id":"903d739b67cd716d","repo":"run-llama/liteparse","slug":"invalid-header-value-empty-header-name","errorCode":null,"errorMessage":"invalid header '${value}', empty header name","messagePattern":"invalid header '(.+?)', empty header name","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/node/src/cli.ts","lineNumber":46,"sourceCode":"    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)\",\n  )\n  .option(\n    \"--image-output-dir <dir>\",\n    \"Directory to write embedded images to when --image-mode embed is set\",","sourceCodeStart":28,"sourceCodeEnd":64,"githubUrl":"https://github.com/run-llama/liteparse/blob/22d2dd8cd7f7b9320102b57ddaf0e663ff7d15a8/packages/node/src/cli.ts#L28-L64","documentation":"collectHeader splits the `--header` value on the first `:` and trims the left side; if the resulting header name is empty (e.g. the value starts with `:`), the header is meaningless and the CLI throws. This guards against silently sending malformed headers to an OCR HTTP server.","triggerScenarios":"Passing `--header \": value\"`, `--header ':'`, or a value like `\": Bearer x\"` where the shell or a quoting mistake dropped the header name before the colon.","commonSituations":"Quoting mistakes where a variable containing the header name expanded to empty (`--header \"$AUTH_HEADER\"` when AUTH_HEADER=': x'); hand-editing scripts and accidentally deleting the name.","solutions":["Provide a non-empty name before the colon: `--header \"Authorization: Bearer <token>\"`.","If building headers from shell variables, verify the variable is non-empty before invoking the CLI.","Log/echo the fully assembled argument list in scripts to catch variables that expanded to nothing."],"exampleFix":"// before\nliteparse parse doc.pdf --header \": Bearer tok\"\n// after\nliteparse parse doc.pdf --header \"Authorization: Bearer tok\"","handlingStrategy":"validation","validationCode":"function hasHeaderName(h) {\n  const i = h.indexOf(':');\n  return i !== -1 && h.slice(0, i).trim() !== '';\n}\nif (!hasHeaderName(flagValue)) throw new Error('header name must be non-empty: ' + flagValue);","typeGuard":"const hasNonEmptyName = (v) => typeof v === 'string' && v.includes(':') && v.slice(0, v.indexOf(':')).trim() !== '';","tryCatchPattern":"try {\n  await program.parseAsync(process.argv);\n} catch (e) {\n  if (e.message.includes('empty header name')) {\n    console.error(`--header value \"${flagValue}\" is missing a name before the colon.`);\n    process.exit(2);\n  }\n  throw e;\n}","preventionTips":["Verify shell variables used in header arguments expand to non-empty values (set -u).","Assemble headers as `\"${name}: ${value}\"` and assert name is non-empty.","Add a startup sanity check that prints the resolved CLI args in scripts."],"tags":["cli","headers","empty-value"],"backgroundTag":"empty-required-field","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"}