JuliusBrussee/caveman · error

usage: verify <bundle.json> [--pubkey ]

Error message

usage: ${invokedCommand("receipts")} verify <bundle.json> [--pubkey <file>]

What it means

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>]`.

Solutions

  1. Provide the bundle path: `caveman receipts verify bundle.json --pubkey keys.json`
  2. Check that the shell variable holding the path is non-empty (`echo "$BUNDLE"`)
  3. Run `caveman receipts verify --help` to confirm argument order

Example fix

# before
caveman receipts verify --pubkey keys.json
# after
caveman receipts verify bundle.json --pubkey keys.json
Defensive patterns

Strategy: validation

Validate before calling

const file = process.argv[3];
if (!file || file.startsWith('--')) { console.error('usage: caveman receipts verify <bundle.json> [--pubkey <file>]'); process.exit(2); }
if (!fs.existsSync(file)) { console.error(`bundle not found: ${file}`); process.exit(2); }

Try / catch

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 }

Prevention

When it happens

Trigger: Running `caveman receipts verify` with no path, or only `--pubkey keys.json` so no positional remains, or quoting errors that swallow the filename.

Common situations: 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.

Understand the failure class

Background: "no subcommand specified" and "... is required": CLI errors when a required argument is missing — this error's family across 13 libraries.

Related errors


AI-assisted analysis of JuliusBrussee/caveman@3ee70a1026 (2026-09-20). Data as JSON: /api/errors/90337d2aa9be018d. Report an issue: GitHub.

Appendix: source

Thrown at packages/cli/src/index.ts:17907

  try { parsed = JSON.parse(source); } catch { throw new Error("--pubkey JSON is malformed"); }
  const infos = Array.isArray(parsed.public_keys) ? parsed.public_keys : parsed.public_key ? [parsed.public_key] : [];
  if (infos.length === 0) throw new Error("--pubkey JSON must contain public_key or public_keys");
  const keys = decodeUniqueKeyring(infos, "--pubkey public_keys");
  const pinnedCurrent = keys.get(current.info.key_id);
  if (!pinnedCurrent || !pinnedCurrent.raw.equals(current.raw)) throw new Error("trusted --pubkey keyring does not contain the bundle public key");
  return { keys, trust: "pinned_keyring" };
}

// receiptsVerify validates a signed receipt bundle offline (no network). A raw
// --pubkey pins the current key; JSON may independently pin a full rotation
// keyring. Without either, embedded keys prove self-consistency, not publisher
// authenticity. Exits non-zero on any included content, signature, or
// scope-chain break. Tail/scope omission needs separately trusted head manifest;
// bundle output states completeness is not attested.
//   caveman receipts verify <bundle.json> [--pubkey <file>]
async function receiptsVerify(argv: string[]) {
  const file = positionalAfterOptions(argv.slice(1), new Set(["--pubkey"]));
  if (!file) throw new Error(`usage: ${invokedCommand("receipts")} verify <bundle.json> [--pubkey <file>]`);
  let bundle: ReceiptBundle;
  try { bundle = JSON.parse(await readFile(file, "utf8")) as ReceiptBundle; } catch (e) { return fail(`invalid bundle JSON: ${(e as Error).message}`); }
  if (!Array.isArray(bundle.receipts)) return fail("bundle receipts must be an array");

  try {
    const embedded = embeddedReceiptKeys(bundle);
    const pubkeyFile = flagFrom(argv, "--pubkey", "");
    const pinned = pubkeyFile ? await pinnedReceiptKeys(pubkeyFile, embedded.current) : null;
    const keys = pinned?.keys ?? embedded.keys;
    for (const receipt of bundle.receipts) {
      const embeddedKey = embedded.keys.get(receipt.signature?.key_id);
      if (!embeddedKey) return fail(`seq ${receipt.seq}: no embedded public key for key_id ${String(receipt.signature?.key_id)}`);
      if (pinned) {
        const trusted = keys.get(receipt.signature?.key_id);
        if (!trusted) return fail(`seq ${receipt.seq}: key_id ${String(receipt.signature?.key_id)} is not present in trusted --pubkey material`);
        if (!trusted.raw.equals(embeddedKey.raw)) return fail(`seq ${receipt.seq}: embedded key ${receipt.signature.key_id} does not match trusted --pubkey material`);
      }
    }

View on GitHub (pinned to 3ee70a1026)