{"record":{"id":"80c43cb8fa10bec4","repo":"JuliusBrussee/caveman","slug":"result-error-message-local-scan-sync-failed-response-status","errorCode":null,"errorMessage":"result.error?.message ?? `local scan sync failed (${response.status})`","messagePattern":"result\\.error\\?\\.message \\?\\? `local scan sync failed \\((.+?)\\)`","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/cli/src/index.ts","lineNumber":10226,"sourceCode":"    body: JSON.stringify(state.payload),\n  });\n  const result = (await response.json().catch(() => ({}))) as {\n    id?: string;\n    project_id?: string;\n    status?: string;\n    source?: string;\n    basis?: string;\n    error?: { message?: string };\n  };\n  if (\n    !response.ok\n    || result.status !== \"completed\"\n    || result.source !== \"local_scan\"\n    || result.basis !== \"inferred\"\n    || typeof result.id !== \"string\"\n    || !result.id\n  ) {\n    throw new Error(result.error?.message ?? `local scan sync failed (${response.status})`);\n  }\n  const delivered: LocalScanState = {\n    ...state,\n    delivered: {\n      import_id: result.id,\n      project_id: typeof result.project_id === \"string\" ? result.project_id : cfg.projectId ?? \"\",\n      organization_id: cfg.organizationId ?? \"\",\n      base_url: cfg.baseURL,\n      delivered_at: new Date().toISOString(),\n    },\n  };\n  mkdirSync(dirname(localScanStatePath()), { recursive: true });\n  writeFileSync(localScanStatePath(), JSON.stringify(delivered, null, 2) + \"\\n\", { mode: 0o600 });\n  return { kind: \"synced\", importId: result.id, dashboard: deriveLocalScanDashboardUrl(cfg.baseURL) };\n}\n\nfunction localScanSyncLine(out: Extract<LocalScanSyncOutcome, { kind: \"synced\" }>): string {\n  const destination = out.dashboard ? ` → ${out.dashboard}` : \"\";","sourceCodeStart":10208,"sourceCodeEnd":10244,"githubUrl":"https://github.com/JuliusBrussee/caveman/blob/3ee70a102609e550bd2e68004bf5990a9341c851/packages/cli/src/index.ts#L10208-L10244","documentation":"Thrown when a local-scan sync POST completes but the response does not describe a successful delivery: either the server returned an error body (its `error.message` is surfaced) or the payload failed shape checks (status must be \"completed\", source \"local_scan\", basis \"inferred\", and a non-empty string `id`). It signals the sync import was not accepted.","triggerScenarios":"Syncing local scan results when the server rejects the payload (validation error), returns a non-completed status, or responds with an unexpected JSON shape missing `id`/`project_id`.","commonSituations":"Gateway version mismatch where the response schema changed (e.g. source/basis values differ); server-side validation rejecting the scan batch; proxy returning an HTML error page parsed as {}; project not provisioned server-side.","solutions":["Read the surfaced `error.message` from the response body shown in the thrown error for the server's reason.","Verify CLI and gateway versions are compatible (response contract: status=completed, source=local_scan, basis=inferred).","Check that the target project exists and the scan payload passes server validation.","If a proxy interferes, hit the gateway directly and inspect the raw response."],"exampleFix":"// before: stale CLI expecting old response shape\nthrow new Error(result.error?.message ?? `local scan sync failed (${response.status})`)\n// after: upgrade CLI to match current gateway response contract\nnpm i -g @caveman/cli@latest && caveman sync","handlingStrategy":"validation","validationCode":"// Validate the expected response contract before treating sync as done\nfunction isDelivered(r) {\n  return r && r.status === \"completed\" && r.source === \"local_scan\" &&\n    r.basis === \"inferred\" && typeof r.id === \"string\" && r.id.length > 0;\n}","typeGuard":"function isSyncResult(v: unknown): v is { status: \"completed\"; source: \"local_scan\"; basis: \"inferred\"; id: string; project_id?: string } {\n  const r = v as Record<string, unknown>;\n  return r.status === \"completed\" && r.source === \"local_scan\" &&\n    r.basis === \"inferred\" && typeof r.id === \"string\" && r.id.length > 0;\n}","tryCatchPattern":"try {\n  await syncLocalScan();\n} catch (e) {\n  console.error(`Local scan sync rejected: ${e.message}`); // server error.message is surfaced first\n  // inspect CLI/gateway version compatibility, then retry after fixing\n}","preventionTips":["Keep CLI and gateway versions in sync — response shape is versioned.","Confirm the target project exists and the scan payload passes server validation.","Check the surfaced error.message before assuming a client bug."],"tags":["sync","api","http","validation"],"backgroundTag":"unexpected-api-response-shape","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"}