{"record":{"id":"61b358a1a9820a5b","repo":"heygen-com/hyperframes","slug":"freeze-failed-content-length-declared-exceeds","errorCode":null,"errorMessage":"freeze failed: content-length ${declared} exceeds ${MAX_FREEZE_BYTES} cap","messagePattern":"freeze failed: content-length (.+?) exceeds (.+?) cap","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/core/src/figma/freeze.ts","lineNumber":57,"sourceCode":"  let parsed: URL;\n  try {\n    parsed = new URL(url);\n  } catch {\n    return false;\n  }\n  if (parsed.protocol !== \"https:\") return false;\n  const host = parsed.hostname;\n  return host === \"figma.com\" || host.endsWith(\".figma.com\") || host.endsWith(\".amazonaws.com\");\n}\n\nexport async function freezeUrl(url: string, destPath: string): Promise<number> {\n  if (!isAllowedFreezeUrl(url))\n    throw new Error(`freeze failed: refusing non-figma url ${url} (https + figma hosts only)`);\n  const res = await fetch(url);\n  if (!res.ok) throw new Error(`freeze failed: HTTP ${res.status}`);\n  const declared = Number(res.headers.get(\"content-length\") ?? 0);\n  if (exceedsFreezeCap(declared))\n    throw new Error(`freeze failed: content-length ${declared} exceeds ${MAX_FREEZE_BYTES} cap`);\n  return freezeBytes(new Uint8Array(await res.arrayBuffer()), destPath);\n}\n\nexport function freezeLocalFile(srcPath: string, destPath: string): void {\n  const size = statSync(srcPath).size;\n  if (exceedsFreezeCap(size))\n    throw new Error(`freeze failed: ${size} bytes exceeds ${MAX_FREEZE_BYTES} cap`);\n  mkdirSync(dirname(destPath), { recursive: true });\n  copyFileSync(srcPath, destPath);\n}\n","sourceCodeStart":39,"sourceCodeEnd":68,"githubUrl":"https://github.com/heygen-com/hyperframes/blob/c2996c8626135db5253519359d8a063d3bafad8d/packages/core/src/figma/freeze.ts#L39-L68","documentation":"Thrown by freezeUrl before downloading the body, when the response's content-length header advertises a size larger than MAX_FREEZE_BYTES (256 MiB). This is the pre-download half of the size cap: it aborts a huge transfer early so the process never buffers hundreds of megabytes, complementing the post-download check in freezeBytes. A declared length of 0 (header absent) is treated as 'unknown' and allowed through to the freezeBytes check, so this throw only fires on an explicit oversized declaration.","triggerScenarios":"A figma render URL whose content-length header reports > 256 MiB; a video asset exported from figma larger than the cap; a server mis-reporting content-length (rare).","commonSituations":"Importing a 4x-scale PNG of a very large frame; freezing a figma-exported video; a figma file with oversized embedded media.","solutions":["Re-render at a lower scale (opts.scale) to shrink the asset below the cap.","Export the asset from figma at a smaller size before importing.","Confirm the content-length is genuine and not a proxy reporting a wrong value.","If the asset legitimately must be huge, raise MAX_FREEZE_BYTES in a fork after reviewing disk budget."],"exampleFix":"// before — 4x scale produces a >256 MiB PNG\nawait client.renderNode(ref, { format: 'png', scale: 4 });\n\n// after — 2x scale stays under the cap\nawait client.renderNode(ref, { format: 'png', scale: 2 });","handlingStrategy":"validation","validationCode":"import { exceedsFreezeCap } from '.../figma/freeze';\nexport function assertDeclaredUnderCap(declared: number): void {\n  if (exceedsFreezeCap(declared)) {\n    throw new Error(`declared size ${declared} exceeds cap — shrink the source asset`);\n  }\n}\n// usage right after the fetch\nconst declared = Number(res.headers.get('content-length') ?? 0);\nassertDeclaredUnderCap(declared);\nawait freezeUrl(url, dest);","typeGuard":null,"tryCatchPattern":"try {\n  await freezeUrl(url, dest);\n} catch (err) {\n  if (err instanceof Error && /content-length .* exceeds/.test(err.message)) {\n    // re-render at lower scale\n  } else throw err;\n}","preventionTips":["Render at the lowest acceptable scale.","Pre-check content-length before downloading to abort huge transfers early.","For video assets, transcode below the cap before importing."],"tags":["figma","freeze","size-limit","validation","assets"],"backgroundTag":null,"analyzedSha":"c2996c8626135db5253519359d8a063d3bafad8d","analyzedAt":"2026-08-12T22:18:56.877Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}