{"record":{"id":"c0a81536bd8a7be3","repo":"jackwener/OpenCLI","slug":"label-file-does-not-exist-ref-value","errorCode":null,"errorMessage":"${label} file does not exist: ${ref.value}","messagePattern":"(.+?) file does not exist: (.+?)","errorType":"validation","errorClass":"ArgumentError","httpStatus":null,"severity":"error","filePath":"clis/midjourney/utils.js","lineNumber":910,"sourceCode":"          return { kind: 'url', value: originalImageUrl(match[1].toLowerCase(), index), source: item };\n        }\n      } catch (error) {\n        if (error instanceof ArgumentError) throw error;\n      }\n      return { kind: 'url', value: item };\n    }\n    const expanded = item === '~' ? os.homedir() : item.startsWith('~/') ? path.join(os.homedir(), item.slice(2)) : item;\n    return { kind: 'local', value: path.resolve(expanded) };\n  });\n}\n\nexport async function validateLocalReferences(refs, label) {\n  for (const ref of refs.filter((item) => item.kind === 'local')) {\n    let stat;\n    try {\n      stat = await fs.stat(ref.value);\n    } catch {\n      throw new ArgumentError(`${label} file does not exist: ${ref.value}`);\n    }\n    if (!stat.isFile() || stat.size <= 0) throw new ArgumentError(`${label} must reference a non-empty file: ${ref.value}`);\n    if (stat.size > MAX_REFERENCE_BYTES) throw new ArgumentError(`${label} exceeds Midjourney's 10MB upload limit: ${ref.value}`);\n    const ext = path.extname(ref.value).toLowerCase();\n    if (!IMAGE_EXTENSIONS.has(ext)) throw new ArgumentError(`${label} must be PNG, JPEG, WEBP, or GIF: ${ref.value}`);\n  }\n  return refs;\n}\n\nasync function visibleImageSources(page) {\n  const payload = unwrapEvaluateResult(await page.evaluate(() => [...document.querySelectorAll('img[src]')]\n    .filter((img) => {\n      const rect = img.getBoundingClientRect();\n      let card = img.parentElement;\n      while (card && !String(card.className).includes('group/img')) card = card.parentElement;\n      return Boolean(card) && rect.width > 24 && rect.height > 24 && /cdn\\.midjourney\\.com\\/u\\//.test(img.src);\n    })\n    .map((img) => img.src)));","sourceCodeStart":892,"sourceCodeEnd":928,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/midjourney/utils.js#L892-L928","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Verify the file exists (ls <path> / fs.existsSync) and correct typos","Use absolute paths or expand ~ and environment variables before passing","Run from the correct working directory or pass paths relative to it","Fix permissions so the process can stat the file"],"exampleFix":"// before\nawait validateLocalReferences([{ kind: 'local', value: '~/img/cat.png' }], 'refs');\n// after\nimport os from 'node:os';\nconst p = '~/img/cat.png'.replace(/^~/, os.homedir());\nawait validateLocalReferences([{ kind: 'local', value: p }], 'refs');","handlingStrategy":"validation","validationCode":"import { stat } from 'node:fs/promises';\nimport os from 'node:os';\nasync function assertFileExists(p) {\n  const abs = p.replace(/^~/, os.homedir());\n  await stat(abs); // throws a clear error before the CLI does\n  return abs;\n}","typeGuard":"const pathExists = async (p) => { try { await fs.stat(p); return true; } catch { return false; } };","tryCatchPattern":"try {\n  await validateLocalReferences(refs, 'refs');\n} catch (e) {\n  if (String(e.message).includes('file does not exist')) {\n    console.error('Fix the path:', e.message);\n  }\n  throw e;\n}","preventionTips":["Use absolute paths or expand ~ and $VARS explicitly","Check the working directory the CLI runs from matches your relative paths","ls/existsSync-check every reference before invoking the CLI","In CI, assert input artifacts exist before the upload step"],"tags":["filesystem","argument-validation","file-not-found"],"backgroundTag":"file-not-found","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}