JuliusBrussee/caveman · error
public_keys must be an array
Error message
public_keys must be an array
What it means
This error is thrown by embeddedReceiptKeys() while decoding a receipt bundle for `caveman receipts verify`. The bundle's `public_keys` field, when present, must be an array of receipt public keys; a non-array value (string, object, null-as-present) means the bundle metadata is malformed, so the CLI refuses to process it.
Solutions
- Fix the bundle so `public_keys` is a JSON array of public key objects
- If only one key exists, remove `public_keys` and keep just `public_key`
- Re-export the bundle with the same caveman CLI version that produced the receipts
Example fix
// before
{"schema":"caveman.receipt-bundle/v2","public_key":{...},"public_keys":{...}}
// after
{"schema":"caveman.receipt-bundle/v2","public_key":{...},"public_keys":[{...}]} Defensive patterns
Strategy: validation
Validate before calling
if (bundle.public_keys !== undefined && !Array.isArray(bundle.public_keys)) throw new Error('public_keys must be an array'); Type guard
const hasKeyring = (b: unknown): b is { public_keys: unknown[] } =>
typeof b === 'object' && b !== null && 'public_keys' in b && Array.isArray((b as any).public_keys); Try / catch
try { verifyBundle(bundle) } catch (e) { if (e.message.includes('public_keys must be an array')) { /* surface bundle-format guidance */ } else throw e } Prevention
- Never hand-edit bundle JSON; re-export with the CLI
- Validate bundle JSON shape with a schema before distributing
- When scripting exports, emit public_keys via JSON.stringify of an array
When it happens
Trigger: Running `caveman receipts verify bundle.json` on a bundle whose top-level JSON contains `public_keys` set to anything other than an array — e.g. a single key object, a comma-separated string, or a dict keyed by key_id.
Common situations: Hand-edited bundle JSON, a script that exported only one key but wrote it under `public_keys`, or a tool from another version producing a v2-shaped bundle with the wrong field type.
Understand the failure class
Background: "Invalid ... format", "must be in format X", "does not look like a ..." — invalid argument format errors across CLI tools and libraries — this error's family across 17 libraries.
Related errors
- v2 bundle requires public_keys
- eval evidence line must be a JSON object
- --pubkey JSON must contain public_key or public_keys
- v2 public_keys must include public_key
- assembly slot content is not JSON-serializable
AI-assisted analysis of JuliusBrussee/caveman@3ee70a1026 (2026-09-20).
Data as JSON: /api/errors/c05d8b15c253a967.
Report an issue: GitHub.
Appendix: source
Thrown at packages/cli/src/index.ts:17871
return { info, raw, key: ed25519PublicKey(raw) };
}
function decodeUniqueKeyring(infos: ReceiptPublicKey[], label: string): Map<string, DecodedReceiptKey> {
const keys = new Map<string, DecodedReceiptKey>();
for (const [index, info] of infos.entries()) {
const decoded = decodeReceiptKey(info, `${label}[${index}]`);
if (keys.has(decoded.info.key_id)) throw new Error(`${label} contains duplicate key_id ${decoded.info.key_id}`);
keys.set(decoded.info.key_id, decoded);
}
return keys;
}
function embeddedReceiptKeys(bundle: ReceiptBundle): { current: DecodedReceiptKey; keys: Map<string, DecodedReceiptKey> } {
if (bundle.schema !== RECEIPT_BUNDLE_V1 && bundle.schema !== RECEIPT_BUNDLE_V2) throw new Error(`unsupported bundle schema ${String(bundle.schema)}`);
if (bundle.verification_coverage !== undefined && bundle.verification_coverage !== INCLUDED_RECEIPTS_ONLY) throw new Error(`unsupported unsigned verification coverage ${String(bundle.verification_coverage)}`);
if (bundle.completeness_attested === true) throw new Error("bundle completeness cannot be attested by unsigned export metadata");
const current = decodeReceiptKey(bundle.public_key, "public_key");
if (bundle.public_keys !== undefined && !Array.isArray(bundle.public_keys)) throw new Error("public_keys must be an array");
if (bundle.schema === RECEIPT_BUNDLE_V2 && (!Array.isArray(bundle.public_keys) || bundle.public_keys.length === 0)) throw new Error("v2 bundle requires public_keys");
const keys = decodeUniqueKeyring(bundle.public_keys ?? [], "public_keys");
const currentInRing = keys.get(current.info.key_id);
if (currentInRing && !currentInRing.raw.equals(current.raw)) throw new Error(`public_key conflicts with public_keys entry ${current.info.key_id}`);
if (bundle.schema === RECEIPT_BUNDLE_V2 && !currentInRing) throw new Error("v2 public_keys must include public_key");
if (!currentInRing) keys.set(current.info.key_id, current);
return { current, keys };
}
async function pinnedReceiptKeys(file: string, current: DecodedReceiptKey): Promise<{ keys: Map<string, DecodedReceiptKey>; trust: string }> {
const source = (await readFile(file, "utf8")).trim();
if (!source.startsWith("{")) {
const pinned = decodeReceiptKey({ ...current.info, key: source }, "--pubkey");
if (!pinned.raw.equals(current.raw)) throw new Error("bundle public key does not match the published --pubkey");
return { keys: new Map([[current.info.key_id, pinned]]), trust: "pinned_public_key" };
}
let parsed: { public_key?: ReceiptPublicKey; public_keys?: ReceiptPublicKey[] };
try { parsed = JSON.parse(source); } catch { throw new Error("--pubkey JSON is malformed"); }View on GitHub (pinned to 3ee70a1026)