jackwener/OpenCLI · error · ArgumentError
${label} must reference a non-empty file: ${ref.value}
Error message
${label} must reference a non-empty file: ${ref.value} What it means
After fs.stat succeeds, the validator requires the reference to be a regular file (stat.isFile()) with size > 0. This ArgumentError is thrown for directories, special files (fifos/devices), and zero-byte files, since Midjourney cannot consume empty or non-file uploads.
Source
Thrown at clis/midjourney/utils.js:912
} catch (error) {
if (error instanceof ArgumentError) throw error;
}
return { kind: 'url', value: item };
}
const expanded = item === '~' ? os.homedir() : item.startsWith('~/') ? path.join(os.homedir(), item.slice(2)) : item;
return { kind: 'local', value: path.resolve(expanded) };
});
}
export async function validateLocalReferences(refs, label) {
for (const ref of refs.filter((item) => item.kind === 'local')) {
let stat;
try {
stat = await fs.stat(ref.value);
} catch {
throw new ArgumentError(`${label} file does not exist: ${ref.value}`);
}
if (!stat.isFile() || stat.size <= 0) throw new ArgumentError(`${label} must reference a non-empty file: ${ref.value}`);
if (stat.size > MAX_REFERENCE_BYTES) throw new ArgumentError(`${label} exceeds Midjourney's 10MB upload limit: ${ref.value}`);
const ext = path.extname(ref.value).toLowerCase();
if (!IMAGE_EXTENSIONS.has(ext)) throw new ArgumentError(`${label} must be PNG, JPEG, WEBP, or GIF: ${ref.value}`);
}
return refs;
}
async function visibleImageSources(page) {
const payload = unwrapEvaluateResult(await page.evaluate(() => [...document.querySelectorAll('img[src]')]
.filter((img) => {
const rect = img.getBoundingClientRect();
let card = img.parentElement;
while (card && !String(card.className).includes('group/img')) card = card.parentElement;
return Boolean(card) && rect.width > 24 && rect.height > 24 && /cdn\.midjourney\.com\/u\//.test(img.src);
})
.map((img) => img.src)));
return Array.isArray(payload) ? payload.map(String) : [];
}View on GitHub (pinned to 49907e53dc)
Solutions
- Point the reference at an actual image file, not a directory or special file
- Check size (ls -l / stat) and re-export/re-download if the file is 0 bytes
- Fix the upstream step that produced the empty file
Example fix
// before --refs ./images/ // directory --refs ./broken-download.png // 0 bytes // after --refs ./images/cat.png // real, non-empty file
Defensive patterns
Strategy: validation
Validate before calling
const s = await fs.stat(p);
if (!s.isFile() || s.size <= 0) throw new Error(`${p} is not a non-empty regular file`); Type guard
const isNonEmptyFile = async (p) => { try { const s = await fs.stat(p); return s.isFile() && s.size > 0; } catch { return false; } }; Try / catch
try {
await validateLocalReferences(refs, 'refs');
} catch (e) {
if (String(e.message).includes('must reference a non-empty file')) {
console.error('Re-generate or re-download the file:', e.message);
}
throw e;
} Prevention
- Never pass directories — point at individual image files
- After downloads, assert size > 0 before continuing the pipeline
- Treat 0-byte files as failed artifacts and re-produce them
When it happens
Trigger: Passing a directory as a reference, passing a 0-byte file left by a failed download or touch, or passing a fifo/socket/device path.
Common situations: An earlier download step failed leaving a 0-byte placeholder, pipelines creating empty output files on error, users passing a folder expecting the tool to pick images from it.
Understand the failure class
Background: "File not found" and ENOENT errors: why libraries can't find a file that should exist — this error's family across 50 libraries.
Related errors
- File not found: ${path}
- File must be a readable text file: ${path}
- Video file is empty: ${filePath}
- 视频文件不存在: ${videoPath}
- Video file not found: ${resolved}
AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29).
Data as JSON: /api/errors/04eb69d6b11466f0.
Report an issue: GitHub.