{"record":{"id":"fe98f7f045de0dbc","repo":"different-ai/openwork","slug":"file-too-large-fe98f7","errorCode":"file-too-large","errorMessage":"Download exceeds the ${maxBytes}-byte limit.","messagePattern":"Download exceeds the (.+?)-byte limit\\.","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"apps/desktop/electron/binary-transfer.mjs","lineNumber":292,"sourceCode":"  let stagingFile;\n  let destinationFile;\n  try {\n    const response = await options.fetcher(url, {\n      method,\n      headers,\n      credentials: \"omit\",\n      cache: \"no-store\",\n      // The endpoint allowlist covers only the initial URL, so a redirect\n      // must never be followed to an unvalidated destination.\n      redirect: \"error\",\n      signal,\n    });\n    if (!response.ok) {\n      return { ...responseMetadata(response), body: await responseText(response), path: null, bytes: 0 };\n    }\n    const declaredLength = Number(response.headers.get(\"content-length\"));\n    if (Number.isFinite(declaredLength) && declaredLength > maxBytes) {\n      throw transferError(`Download exceeds the ${maxBytes}-byte limit.`, \"file-too-large\");\n    }\n    await mkdir(stagingDir, { recursive: true });\n    stagingPath = path.join(stagingDir, `download-${randomUUID()}.part`);\n    stagingFile = await open(stagingPath, \"wx+\");\n    const reader = response.body?.getReader();\n    let bytes = 0;\n    if (reader) {\n      while (true) {\n        signal?.throwIfAborted();\n        const { done, value } = await reader.read();\n        if (done) break;\n        bytes += value.byteLength;\n        if (bytes > maxBytes) {\n          await reader.cancel();\n          throw transferError(`Download exceeds the ${maxBytes}-byte limit.`, \"file-too-large\");\n        }\n        await writeAll(stagingFile, value);\n      }","sourceCodeStart":274,"sourceCodeEnd":310,"githubUrl":"https://github.com/different-ai/openwork/blob/2b7df46e8ae1517d64c896c7793d2d52ec845669/apps/desktop/electron/binary-transfer.mjs#L274-L310","documentation":"downloadBinaryToPath checks the HTTP Content-Length header before writing anything and throws code 'file-too-large' when the declared body exceeds maxBytes. This is a pre-flight guard so oversized files are rejected without consuming disk or bandwidth. The default limit is DESKTOP_TRANSFER_MAX_BYTES (250 MB) when a caller does not supply a smaller one.","triggerScenarios":"Calling downloadBinaryToPath where the server response's content-length header is a finite number greater than maxBytes; the throw happens before any bytes are read.","commonSituations":"Downloading model binaries, releases, or dataset archives larger than the configured limit; a caller passing a very small maxBytes for a legitimately large asset; a misconfigured server advertising a huge file.","solutions":["Raise the maxBytes option passed to downloadBinaryToPath (or use DESKTOP_TRANSFER_MAX_BYTES) to cover the expected asset size.","Verify the URL points at the intended, correctly-sized resource (HEAD request first to inspect content-length).","If the file genuinely must exceed limits, download in chunks/ranges or stream via a different mechanism with your own quota handling."],"exampleFix":"// before\nawait downloadBinaryToPath({ url, destinationPath, maxBytes: 10_000_000 }); // 10 MB limit, asset is 80 MB\n// after\nimport { DESKTOP_TRANSFER_MAX_BYTES } from \"./binary-transfer.mjs\";\nawait downloadBinaryToPath({ url, destinationPath, maxBytes: DESKTOP_TRANSFER_MAX_BYTES });","handlingStrategy":"validation","validationCode":"const head = await fetch(url, { method: \"HEAD\" });\nconst len = Number(head.headers.get(\"content-length\"));\nif (Number.isFinite(len) && len > maxBytes) throw new Error(`Refusing download: ${len} bytes > ${maxBytes} limit`);","typeGuard":"function isWithinLimit(contentLength, maxBytes) {\n  return typeof contentLength === \"number\" && Number.isFinite(contentLength) && contentLength >= 0 && contentLength <= maxBytes;\n}","tryCatchPattern":"try {\n  await downloadBinaryToPath({ url, destinationPath, maxBytes });\n} catch (e) {\n  if (e?.code === \"file-too-large\") {\n    console.error(`Asset exceeds ${maxBytes} bytes; raise maxBytes or pick a smaller artifact.`);\n    return;\n  }\n  throw e;\n}","preventionTips":["HEAD-probe the URL and compare content-length against maxBytes before downloading.","Use the exported DESKTOP_TRANSFER_MAX_BYTES default instead of ad-hoc small limits.","Surface the limit in user-facing config so operators know why big assets fail."],"tags":["download","size-limit","network"],"backgroundTag":"download-size-limit-exceeded","analyzedSha":"2b7df46e8ae1517d64c896c7793d2d52ec845669","analyzedAt":"2026-09-01T07:59:23.713Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}