different-ai/openwork · error
file-too-large
file-too-large
Error message
Download exceeds the ${maxBytes}-byte limit. What it means
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.
Source
Thrown at apps/desktop/electron/binary-transfer.mjs:292
let stagingFile;
let destinationFile;
try {
const response = await options.fetcher(url, {
method,
headers,
credentials: "omit",
cache: "no-store",
// The endpoint allowlist covers only the initial URL, so a redirect
// must never be followed to an unvalidated destination.
redirect: "error",
signal,
});
if (!response.ok) {
return { ...responseMetadata(response), body: await responseText(response), path: null, bytes: 0 };
}
const declaredLength = Number(response.headers.get("content-length"));
if (Number.isFinite(declaredLength) && declaredLength > maxBytes) {
throw transferError(`Download exceeds the ${maxBytes}-byte limit.`, "file-too-large");
}
await mkdir(stagingDir, { recursive: true });
stagingPath = path.join(stagingDir, `download-${randomUUID()}.part`);
stagingFile = await open(stagingPath, "wx+");
const reader = response.body?.getReader();
let bytes = 0;
if (reader) {
while (true) {
signal?.throwIfAborted();
const { done, value } = await reader.read();
if (done) break;
bytes += value.byteLength;
if (bytes > maxBytes) {
await reader.cancel();
throw transferError(`Download exceeds the ${maxBytes}-byte limit.`, "file-too-large");
}
await writeAll(stagingFile, value);
}View on GitHub (pinned to 2b7df46e8a)
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.
Example fix
// before
await downloadBinaryToPath({ url, destinationPath, maxBytes: 10_000_000 }); // 10 MB limit, asset is 80 MB
// after
import { DESKTOP_TRANSFER_MAX_BYTES } from "./binary-transfer.mjs";
await downloadBinaryToPath({ url, destinationPath, maxBytes: DESKTOP_TRANSFER_MAX_BYTES }); Defensive patterns
Strategy: validation
Validate before calling
const head = await fetch(url, { method: "HEAD" });
const len = Number(head.headers.get("content-length"));
if (Number.isFinite(len) && len > maxBytes) throw new Error(`Refusing download: ${len} bytes > ${maxBytes} limit`); Type guard
function isWithinLimit(contentLength, maxBytes) {
return typeof contentLength === "number" && Number.isFinite(contentLength) && contentLength >= 0 && contentLength <= maxBytes;
} Try / catch
try {
await downloadBinaryToPath({ url, destinationPath, maxBytes });
} catch (e) {
if (e?.code === "file-too-large") {
console.error(`Asset exceeds ${maxBytes} bytes; raise maxBytes or pick a smaller artifact.`);
return;
}
throw e;
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- zero-byte-file
- latest-mac.yml is missing artifact path/url.
- Failed to fetch latest-mac.yml (${response.status} ${respons
- Request timed out.
- Timed out waiting for server health
AI-assisted analysis of different-ai/openwork@2b7df46e8a (2026-09-01).
Data as JSON: /api/errors/fe98f7f045de0dbc.
Report an issue: GitHub.