jackwener/OpenCLI · error · ArgumentError

${label} file does not exist: ${ref.value}

Error message

${label} file does not exist: ${ref.value}

What it means

validateLocalReferences stats every local-kind reference. If fs.stat rejects (ENOENT, permission error, invalid path), the library cannot verify the file and throws this ArgumentError naming the path, failing fast before any browser-based upload starts.

Source

Thrown at clis/midjourney/utils.js:910

          return { kind: 'url', value: originalImageUrl(match[1].toLowerCase(), index), source: item };
        }
      } 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)));

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Verify the file exists (ls <path> / fs.existsSync) and correct typos
  2. Use absolute paths or expand ~ and environment variables before passing
  3. Run from the correct working directory or pass paths relative to it
  4. Fix permissions so the process can stat the file

Example fix

// before
await validateLocalReferences([{ kind: 'local', value: '~/img/cat.png' }], 'refs');
// after
import os from 'node:os';
const p = '~/img/cat.png'.replace(/^~/, os.homedir());
await validateLocalReferences([{ kind: 'local', value: p }], 'refs');
Defensive patterns

Strategy: validation

Validate before calling

import { stat } from 'node:fs/promises';
import os from 'node:os';
async function assertFileExists(p) {
  const abs = p.replace(/^~/, os.homedir());
  await stat(abs); // throws a clear error before the CLI does
  return abs;
}

Type guard

const pathExists = async (p) => { try { await fs.stat(p); return true; } catch { return false; } };

Try / catch

try {
  await validateLocalReferences(refs, 'refs');
} catch (e) {
  if (String(e.message).includes('file does not exist')) {
    console.error('Fix the path:', e.message);
  }
  throw e;
}

Prevention

When it happens

Trigger: A local reference whose path does not exist, a typo'd filename, a deleted temp file, an unexpanded ~ or $VAR in the path, or a file the process cannot access.

Common situations: Running the CLI from a different working directory than intended, CI environments where the image was never produced, tilde paths in cron/systemd that never expand, Windows backslash paths pasted into a POSIX shell.

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


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