jackwener/OpenCLI · error · CommandExecutionError
Could not write Midjourney image ${filePath}: ${errorMessage
Error message
Could not write Midjourney image ${filePath}: ${errorMessage(error)} What it means
Writing the downloaded image bytes to filePath failed at the filesystem level (temp write or atomic rename). The temp .part file is cleaned up and the underlying OS error is surfaced via errorMessage(error).
Source
Thrown at clis/midjourney/utils.js:684
if (media.mime !== actualMime) {
log.warn(`Midjourney CDN reported ${media.mime || 'unknown'} for ${resolved.url}; detected ${actualMime} from file bytes`);
}
const extension = actualMime === 'image/png'
? '.png'
: actualMime === 'image/webp'
? '.webp'
: actualMime === 'image/gif'
? '.gif'
: '.jpg';
const filePath = path.join(outputDir, `${jobId}_${index}${extension}`);
const tempPath = `${filePath}.part-${process.pid}-${Date.now()}`;
try {
await fs.writeFile(tempPath, media.buffer);
await fs.rename(tempPath, filePath);
} catch (error) {
await fs.unlink(tempPath).catch(() => {});
throw new CommandExecutionError(`Could not write Midjourney image ${filePath}: ${errorMessage(error)}`);
}
return { index, filePath, bytes: media.buffer.length, url: resolved.url, mime: actualMime, cached: false };
}
export async function downloadOriginals(page, jobId, indices, outputDir, force = false) {
await fs.mkdir(outputDir, { recursive: true });
const files = [];
for (const index of indices) files.push(await downloadOne(page, jobId, index, outputDir, force));
return files;
}
export function rawVideoUrl(jobId, index) {
return `${MIDJOURNEY_CDN}/video/${jobId}/${index}.mp4`;
}
async function writeMediaBuffer(filePath, buffer) {
const tempPath = `${filePath}.part-${process.pid}-${Date.now()}`;
try {View on GitHub (pinned to 49907e53dc)
Solutions
- Check that outputDir exists and is writable (mkdir -p, check permissions).
- Free disk space if ENOSPC is reported.
- Fix permissions on the output path or run with a user that can write there.
- Ensure filePath is valid and not too long for the filesystem.
Example fix
// before
await downloadOriginals(page, jobId, [0], '/read-only/out');
// after
await fs.mkdir('/data/out', { recursive: true });
await downloadOriginals(page, jobId, [0], '/data/out'); Defensive patterns
Strategy: validation
Validate before calling
import fs from 'node:fs/promises';
await fs.mkdir(outputDir, { recursive: true });
await fs.access(outputDir, fs.constants.W_OK); Try / catch
try {
await downloadOriginals(page, jobId, indices, outDir);
} catch (err) {
if (/Could not write Midjourney image/.test(err.message)) {
await fs.mkdir(outDir, { recursive: true });
if (err.message.includes('ENOSPC')) throw new Error('Free disk space required');
await downloadOriginals(page, jobId, indices, outDir);
} else throw err;
} Prevention
- Create the output directory with { recursive: true } before downloading.
- Check write permissions and disk space before batch downloads.
- Avoid read-only or network mounts as output destinations.
- Run the CLI as a user with write access to the target path.
When it happens
Trigger: The output directory does not exist or is not writable; disk full (ENOSPC); permission denied on the target path; target path too long or on a read-only mount; fs.rename fails across devices or on a locked file.
Common situations: Wrong output directory configured; running in a container with a read-only volume; quota/disk-space exhaustion on large image batches; antivirus locking files on Windows.
Related errors
- Could not write Midjourney media ${filePath}: ${errorMessage
- Short read on part ${partNumber}: expected ${chunkSize} byte
- Could not store Midjourney ${kind} at ${filePath}: ${errorMe
- Could not read Midjourney usage snapshots: ${errorMessage(er
- Could not persist Twitter likes resume state: ${error instan
AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29).
Data as JSON: /api/errors/5ed7a55bbcf2b744.
Report an issue: GitHub.