{"record":{"id":"59d5bd171cc58c6e","repo":"JuliusBrussee/caveman","slug":"value-is-not-json-serializable","errorCode":null,"errorMessage":"value is not JSON-serializable","messagePattern":"value is not JSON-serializable","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/sdk/typescript/src/index.ts","lineNumber":1952,"sourceCode":"\n  const prefixHash = sha256Hex(prefixBytes);\n  const assemblyHeader = `v1;slots=${ordered.length};prefix=${prefixHash.slice(0, 12)};vbb=1`;\n  assemblyRequestHeaders.set(request, assemblyHeader);\n  return {\n    request,\n    headers: { \"x-cave-assembly\": assemblyHeader },\n    prefixHash,\n    breakpoints,\n    stableTokens: Math.ceil(new TextEncoder().encode(prefixBytes).length / 4),\n    tokenBasis: \"estimated_bytes_div_4\",\n    basis: \"inferred\",\n    volatileBelowBreakpoint: true\n  };\n}\n\nfunction canonicalJSON(value: unknown): string {\n  const raw = JSON.stringify(value);\n  if (raw === undefined) throw new Error(\"value is not JSON-serializable\");\n  return stableStringify(JSON.parse(raw));\n}\n\nfunction cloneCanonical(value: unknown): unknown {\n  return JSON.parse(canonicalJSON(value)) as unknown;\n}\n\nfunction assemblyText(value: unknown): string {\n  return typeof value === \"string\" ? value : canonicalJSON(value);\n}\n\nasync function cavePlan(cave: Cave): Promise<CavePlan> {\n  // `/sdk/v1/cave-plan` is a gateway-owned project-key route. `controlURL` is\n  // reserved for control-api `/api/v1/*` surfaces and must never redirect this\n  // call to a route that service does not expose.\n  const response = await caveFetch(cave, `${cave.options.baseURL}/sdk/v1/cave-plan`, {\n    method: \"GET\",\n    headers: otlpHeaders(cave)","sourceCodeStart":1934,"sourceCodeEnd":1970,"githubUrl":"https://github.com/JuliusBrussee/caveman/blob/3ee70a102609e550bd2e68004bf5990a9341c851/packages/sdk/typescript/src/index.ts#L1934-L1970","documentation":"Thrown by canonicalJSON when JSON.stringify returns undefined, meaning the value contains something JSON cannot represent (a bare function, undefined, Symbol, or a BigInt at top level). Assembly headers and hashes need exact canonical bytes, so serialization failure is fatal rather than coerced.","triggerScenarios":"Thrown at packages/sdk/typescript/src/index.ts:1952 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Pass only plain JSON data (strings, numbers, booleans, null, arrays, objects) as slot/prefix content","Convert BigInt values to strings before serializing","Strip undefined-valued properties or function references from the payload"],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"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"}