jackwener/OpenCLI · error · CommandExecutionError
Midjourney media download returned an empty file from ${url}
Error message
Midjourney media download returned an empty file from ${url} What it means
The download produced zero bytes (or a non-integer/non-positive size), so the file would be empty. The library treats empty payloads as a hard failure rather than writing a 0-byte file to disk.
Source
Thrown at clis/midjourney/utils.js:564
return {
ok: true,
status: response.status,
type: response.headers.get('content-type') || '',
size: bytes.length,
};
}, url, transferKey));
} catch (error) {
throw new CommandExecutionError(`Midjourney browser-context media fetch failed: ${errorMessage(error)}`);
}
if (!payload || typeof payload !== 'object' || !payload.ok) {
throw new CommandExecutionError(`Midjourney media download failed: HTTP ${payload?.status ?? 0} from ${url}`);
}
if (!String(payload.type || '').startsWith(expectedMimePrefix)) {
throw new CommandExecutionError(`Midjourney media download returned unexpected content type "${payload.type || 'unknown'}"`);
}
const size = Number(payload.size);
if (!Number.isInteger(size) || size <= 0) {
throw new CommandExecutionError(`Midjourney media download returned an empty file from ${url}`);
}
// Returning a complete base64 file in one Browser Bridge response can
// exceed the daemon message limit. Pull it out in bounded chunks instead.
const parts = [];
const chunkSize = 96 * 1024;
for (let offset = 0; offset < size; offset += chunkSize) {
const base64 = unwrapEvaluateResult(await page.evaluate((key, start, length) => {
const bytes = window[key];
if (!(bytes instanceof Uint8Array)) return null;
const chunk = bytes.subarray(start, Math.min(bytes.length, start + length));
let binary = '';
const binaryChunkSize = 0x8000;
for (let index = 0; index < chunk.length; index += binaryChunkSize) {
binary += String.fromCharCode(...chunk.subarray(index, index + binaryChunkSize));
}
return btoa(binary);
}, transferKey, offset, chunkSize));View on GitHub (pinned to 49907e53dc)
Solutions
- Retry the download; often transient.
- Check the job status first to confirm the media actually exists.
- Re-resolve the media URL and verify it serves bytes (e.g. via curl).
- Wait until the job fully completes before downloading.
Defensive patterns
Strategy: retry
Validate before calling
const res = await fetch(url, { method: 'HEAD' });
const len = Number(res.headers.get('content-length') || 0);
if (!len) throw new Error('No content at ' + url + '; job media may not exist yet'); Try / catch
try {
await downloadMedia(page, url);
} catch (err) {
if (/empty file/.test(err.message)) {
await sleep(5000);
await downloadMedia(page, url); // transient empty responses often resolve
} else throw err;
} Prevention
- Confirm the job reached a completed status before downloading.
- Retry with delay; empty 200s from CDNs are frequently transient.
- Verify the URL serves bytes out-of-band (curl -I) when debugging.
- Avoid downloading immediately at job creation time.
When it happens
Trigger: The CDN returned HTTP 200 with an empty body; the in-page buffer reported a size of 0 or a non-numeric size; a redirect to an empty resource.
Common situations: Midjourney CDN serving empty responses for just-deleted or not-yet-finished media; transient CDN faults; fetching media for a job whose generation silently failed.
Related errors
- Midjourney media download returned unexpected content type "
- operation must be one of: ${ACTION_CHOICES.join(', ')}
- Midjourney media download failed: HTTP ${payload?.status ??
- Midjourney original image returned invalid media bytes from
- Rendered video kind must be video-social or gif
AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29).
Data as JSON: /api/errors/1fc32333080e1934.
Report an issue: GitHub.