jackwener/OpenCLI · error · ArgumentError

${preparedImages.reason}

Error message

${preparedImages.reason}

What it means

When --image paths are supplied, the command calls prepareChatGPTImagePaths to resolve/validate each path; if it returns { ok: false, reason }, the command surfaces the reason verbatim as an ArgumentError. This means at least one image path could not be prepared (missing file, unreadable, unsupported, or not a valid local path).

Source

Thrown at clis/chatgpt/image.js:93

        { name: 'project', valueRequired: true, help: 'Start image generation inside a ChatGPT project ID or /g/g-p-<id> URL' },
        { name: 'op', help: 'Output directory (default: ~/Pictures/chatgpt)' },
        { name: 'sd', type: 'boolean', default: false, help: 'Skip download shorthand; only show ChatGPT link' },
        { name: 'timeout', type: 'int', required: false, default: 240, help: 'Max seconds for the overall command (default: 240)' },
    ],
    columns: ['status', 'file', 'link'],
    func: async (page, kwargs) => {
        const prompt = kwargs.prompt;
        const imagePaths = parseImagePaths(kwargs.image);
        const outputDir = resolveOutputDir(kwargs.op);
        const skipDownloadRaw = kwargs.sd;
        const skipDownload = skipDownloadRaw === '' || skipDownloadRaw === true || normalizeBooleanFlag(skipDownloadRaw);
        const timeout = kwargs.timeout;
        if (!Number.isInteger(timeout) || timeout < 1) {
            throw new ArgumentError('--timeout must be a positive integer (seconds)');
        }
        const preparedImages = imagePaths.length ? await prepareChatGPTImagePaths(imagePaths) : { ok: true, paths: [] };
        if (!preparedImages.ok) {
            throw new ArgumentError(preparedImages.reason);
        }

        // Navigate with full reload to clear React sidebar state before editing the draft.
        if (kwargs.project) {
            await navigateToProject(page, kwargs.project);
        } else {
            await page.goto(`https://${CHATGPT_DOMAIN}/new`, { settleMs: 2000 });
        }
        await clearChatGPTDraft(page);

        if (imagePaths.length) {
            let upload;
            try {
                upload = await uploadChatGPTImages(page, preparedImages.paths);
            } catch (err) {
                throw new CommandExecutionError(`Failed to upload image to ChatGPT: ${err instanceof Error ? err.message : String(err)}`);
            }
            if (!upload?.ok) throw new CommandExecutionError(upload?.reason || 'Failed to upload image to ChatGPT');

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Read the reason in the error message — it names the offending path/problem.
  2. Verify each --image path exists with ls (or fs.existsSync) and is readable.
  3. Use absolute paths, comma-separated for multiple images: --image /abs/a.png,/abs/b.jpg.
  4. Confirm the files are actual image files (png/jpg/webp/gif) the library supports.

Example fix

// before
opencli chatgpt image "edit this" --image ~/screenshots/shot.png
# (file is actually at ~/Desktop/shot.png)
// after
opencli chatgpt image "edit this" --image ~/Desktop/shot.png
Defensive patterns

Strategy: validation

Validate before calling

import fs from 'node:fs';
const imagePaths = 'a.png, b.jpg'.split(',').map(p => p.trim()).filter(Boolean);
for (const p of imagePaths) {
  if (!fs.existsSync(p) || !fs.statSync(p).isFile()) {
    throw new Error(`Image path not found: ${p}`);
  }
}

Type guard

const isExistingFile = (p) => { try { return fs.statSync(p).isFile(); } catch { return false; } };

Try / catch

try {
  await run('chatgpt image', prompt, '--image', imagePaths.join(','));
} catch (err) {
  if (String(err.message).match(/no such file|not found|ENOENT/i)) {
    console.error('Fix the --image path(s) reported in the message and retry');
  } else throw err;
}

Prevention

When it happens

Trigger: `opencli chatgpt image "prompt" --image /nonexistent.png` (or a comma-separated list where any entry fails) causing prepareChatGPTImagePaths to return ok:false with a reason string, which is thrown at image.js:93.

Common situations: Typos in file paths; file deleted or moved between planning and execution; relative paths resolved from an unexpected working directory; passing URLs instead of local files; missing read permissions.

Related errors


AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29). Data as JSON: /api/errors/8dbaba1b0ea1e0bb. Report an issue: GitHub.