{"record":{"id":"90337d2aa9be018d","repo":"JuliusBrussee/caveman","slug":"usage-invokedcommand-receipts-verify-bundl","errorCode":null,"errorMessage":"usage: ${invokedCommand(\"receipts\")} verify <bundle.json> [--pubkey <file>]","messagePattern":"usage: (.+?) verify <bundle\\.json> \\[--pubkey <file>\\]","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/cli/src/index.ts","lineNumber":17907,"sourceCode":"  try { parsed = JSON.parse(source); } catch { throw new Error(\"--pubkey JSON is malformed\"); }\n  const infos = Array.isArray(parsed.public_keys) ? parsed.public_keys : parsed.public_key ? [parsed.public_key] : [];\n  if (infos.length === 0) throw new Error(\"--pubkey JSON must contain public_key or public_keys\");\n  const keys = decodeUniqueKeyring(infos, \"--pubkey public_keys\");\n  const pinnedCurrent = keys.get(current.info.key_id);\n  if (!pinnedCurrent || !pinnedCurrent.raw.equals(current.raw)) throw new Error(\"trusted --pubkey keyring does not contain the bundle public key\");\n  return { keys, trust: \"pinned_keyring\" };\n}\n\n// receiptsVerify validates a signed receipt bundle offline (no network). A raw\n// --pubkey pins the current key; JSON may independently pin a full rotation\n// keyring. Without either, embedded keys prove self-consistency, not publisher\n// authenticity. Exits non-zero on any included content, signature, or\n// scope-chain break. Tail/scope omission needs separately trusted head manifest;\n// bundle output states completeness is not attested.\n//   caveman receipts verify <bundle.json> [--pubkey <file>]\nasync function receiptsVerify(argv: string[]) {\n  const file = positionalAfterOptions(argv.slice(1), new Set([\"--pubkey\"]));\n  if (!file) throw new Error(`usage: ${invokedCommand(\"receipts\")} verify <bundle.json> [--pubkey <file>]`);\n  let bundle: ReceiptBundle;\n  try { bundle = JSON.parse(await readFile(file, \"utf8\")) as ReceiptBundle; } catch (e) { return fail(`invalid bundle JSON: ${(e as Error).message}`); }\n  if (!Array.isArray(bundle.receipts)) return fail(\"bundle receipts must be an array\");\n\n  try {\n    const embedded = embeddedReceiptKeys(bundle);\n    const pubkeyFile = flagFrom(argv, \"--pubkey\", \"\");\n    const pinned = pubkeyFile ? await pinnedReceiptKeys(pubkeyFile, embedded.current) : null;\n    const keys = pinned?.keys ?? embedded.keys;\n    for (const receipt of bundle.receipts) {\n      const embeddedKey = embedded.keys.get(receipt.signature?.key_id);\n      if (!embeddedKey) return fail(`seq ${receipt.seq}: no embedded public key for key_id ${String(receipt.signature?.key_id)}`);\n      if (pinned) {\n        const trusted = keys.get(receipt.signature?.key_id);\n        if (!trusted) return fail(`seq ${receipt.seq}: key_id ${String(receipt.signature?.key_id)} is not present in trusted --pubkey material`);\n        if (!trusted.raw.equals(embeddedKey.raw)) return fail(`seq ${receipt.seq}: embedded key ${receipt.signature.key_id} does not match trusted --pubkey material`);\n      }\n    }","sourceCodeStart":17889,"sourceCodeEnd":17925,"githubUrl":"https://github.com/JuliusBrussee/caveman/blob/3ee70a102609e550bd2e68004bf5990a9341c851/packages/cli/src/index.ts#L17889-L17925","documentation":"receiptsVerify() requires the bundle file path as the first positional argument. If none is present, it throws a usage message showing the correct invocation `caveman receipts verify <bundle.json> [--pubkey <file>]`.","triggerScenarios":"Running `caveman receipts verify` with no path, or only `--pubkey keys.json` so no positional remains, or quoting errors that swallow the filename.","commonSituations":"Typing the subcommand from memory, copying a command where the bundle path variable was empty, or putting --pubkey before a path that doesn't exist so it's consumed as the positional.","solutions":["Provide the bundle path: `caveman receipts verify bundle.json --pubkey keys.json`","Check that the shell variable holding the path is non-empty (`echo \"$BUNDLE\"`)","Run `caveman receipts verify --help` to confirm argument order"],"exampleFix":"# before\ncaveman receipts verify --pubkey keys.json\n# after\ncaveman receipts verify bundle.json --pubkey keys.json","handlingStrategy":"validation","validationCode":"const file = process.argv[3];\nif (!file || file.startsWith('--')) { console.error('usage: caveman receipts verify <bundle.json> [--pubkey <file>]'); process.exit(2); }\nif (!fs.existsSync(file)) { console.error(`bundle not found: ${file}`); process.exit(2); }","typeGuard":null,"tryCatchPattern":"try { await receiptsVerify(argv) } catch (e) { if (e.message.startsWith('usage:')) { e.message.split('\\n').forEach(l => console.error(l)); process.exit(2); } throw e }","preventionTips":["Quote the bundle path in shell scripts: \"$BUNDLE\"","Check variables for emptiness before building the command","Keep --pubkey after the positional path"],"tags":["cli","usage","missing-argument"],"backgroundTag":"missing-cli-argument","analyzedSha":"3ee70a102609e550bd2e68004bf5990a9341c851","analyzedAt":"2026-09-20T15:53:39.229Z","contentChangedAt":"2026-09-20T15:53:39.229Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}