{"record":{"id":"94bef159b6aa1488","repo":"JuliusBrussee/caveman","slug":"eval-evidence-import-failed-response-status","errorCode":null,"errorMessage":"eval evidence import failed (${response.status}): ${JSON.stringify(body)}","messagePattern":"eval evidence import failed \\((.+?)\\): (.+?)","errorType":"http","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/cli/src/index.ts","lineNumber":17637,"sourceCode":"  if (items.length === 0) throw new Error(\"eval evidence file contains no records\");\n\n  const cfg = await config();\n  const project = flagFrom(argv, \"--project\", cfg.projectId ?? \"\");\n  const response = await fetch(`${cfg.baseURL}/api/v1/eval-evidence/batches`, {\n    method: \"POST\",\n    headers: {\n      authorization: `Bearer ${cfg.token}`,\n      \"content-type\": \"application/json\",\n      \"x-cave-csrf\": \"cli\",\n    },\n    body: JSON.stringify({\n      ...(project ? { project_id: project } : {}),\n      dry_run: argv.includes(\"--dry-run\"),\n      items,\n    }),\n  });\n  const body = await response.json();\n  if (!response.ok) throw new Error(`eval evidence import failed (${response.status}): ${JSON.stringify(body)}`);\n  print(body);\n}\n\n// ---------------------------------------------------------------------------\n// Signed usage receipts: air-gapped export + offline verification.\n//\n// A receipt is a per-(org,project,day) aggregate, Ed25519-signed and chained by\n// prev_receipt_hash. `verify` recomputes each canonical hash, checks the\n// signature against the published public key, and walks the chain — all offline,\n// so finance (either party) can re-derive trust without contacting Caveman. It is\n// the cross-language counterpart of cloud/metering's VerifyChain.\n// ---------------------------------------------------------------------------\n\ntype ReceiptSignature = { alg: string; key_id: string; sig: string };\ntype ReceiptScope = { org_hash: string; project_hash: string };\ntype ReceiptOptimizer = { optimizer_id_hash: string; requests_optimized: number };\ntype Receipt = {\n  schema: string;","sourceCodeStart":17619,"sourceCodeEnd":17655,"githubUrl":"https://github.com/JuliusBrussee/caveman/blob/3ee70a102609e550bd2e68004bf5990a9341c851/packages/cli/src/index.ts#L17619-L17655","documentation":"Thrown by the `eval evidence import` CLI command after the HTTP POST to the eval evidence import endpoint returns a non-2xx response. The error embeds the HTTP status code and the JSON body returned by the server so the developer can see the API's own error detail. It means the server rejected the import request (bad payload, auth, project, or server-side validation failure), not that the request failed to send.","triggerScenarios":"Running the eval evidence import command with --dry-run or a set of items and the server responds with status >= 400; e.g. invalid item payloads, expired/missing auth token, unknown project_id, or server-side validation errors reported in the response body.","commonSituations":"Importing evidence after the CLI's token expired; posting items that violate the server's schema after an API version bump; pointing the CLI at the wrong environment (staging URL with a project_id that only exists in prod); server returns 422 with field-level errors in the body.","solutions":["Read the JSON body embedded in the error message — it usually names the exact field or reason the server rejected the import.","Re-authenticate (refresh/login) if the status is 401/403, then retry the import.","Verify the project_id and endpoint URL match the intended environment.","Run with --dry-run first to let the server validate items without committing them."],"exampleFix":"// before\nawait importEvidence(items); // throws: eval evidence import failed (422): {\"error\":\"invalid item schema\"}\n// after\ntry {\n  await importEvidence(items);\n} catch (e) {\n  console.error(\"import rejected:\", (e as Error).message);\n  process.exitCode = 1;\n}","handlingStrategy":"try-catch","validationCode":"if (!items.length) throw new Error('no items to import');\nif (!process.env.API_TOKEN) throw new Error('not authenticated');","typeGuard":null,"tryCatchPattern":"try {\n  await importEvidence(items);\n} catch (e) {\n  const m = /import failed \\((\\d+)\\): (.*)/.exec((e as Error).message);\n  if (m) console.error(`HTTP ${m[1]}:`, m[2]);\n  process.exitCode = 1;\n}","preventionTips":["Always run with --dry-run first to validate items server-side.","Refresh auth tokens before long batch imports.","Check the response body in the error message — it names the rejected field."],"tags":["cli","http","api"],"backgroundTag":"http-error-response","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"}