{"record":{"id":"63252db605eebeef","repo":"jackwener/OpenCLI","slug":"file-not-found-63252d","errorCode":"FILE_NOT_FOUND","errorMessage":"FILE_NOT_FOUND","messagePattern":"FILE_NOT_FOUND","errorType":"error_code","errorClass":"CliError","httpStatus":null,"severity":"error","filePath":"clis/yollomi/utils.js","lineNumber":81,"sourceCode":"                    : 'Check the model and parameters');\n    }\n    try {\n        return JSON.parse(result.body);\n    }\n    catch {\n        throw new CliError('API_ERROR', 'Invalid JSON response', 'Try again');\n    }\n}\n/**\n * Resolve an image input: local file → base64 data URL, URL → as-is.\n */\nexport function resolveImageInput(input) {\n    if (input.startsWith('http://') || input.startsWith('https://') || input.startsWith('data:')) {\n        return input;\n    }\n    const resolved = path.resolve(input);\n    if (!fs.existsSync(resolved)) {\n        throw new CliError('FILE_NOT_FOUND', `File not found: ${resolved}`, 'Provide a valid file path or URL');\n    }\n    const ext = path.extname(resolved).toLowerCase();\n    const mimeMap = {\n        '.jpg': 'image/jpeg', '.jpeg': 'image/jpeg',\n        '.png': 'image/png', '.gif': 'image/gif',\n        '.webp': 'image/webp', '.bmp': 'image/bmp',\n    };\n    const mime = mimeMap[ext] || 'image/png';\n    const data = fs.readFileSync(resolved);\n    return `data:${mime};base64,${data.toString('base64')}`;\n}\nexport async function downloadOutput(url, outputDir, filename) {\n    fs.mkdirSync(outputDir, { recursive: true });\n    const destPath = path.join(outputDir, filename);\n    const resp = await fetch(url);\n    if (!resp.ok)\n        throw new CliError('DOWNLOAD_ERROR', `Download failed: HTTP ${resp.status}`, 'URL may have expired');\n    const buffer = Buffer.from(await resp.arrayBuffer());","sourceCodeStart":63,"sourceCodeEnd":99,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/yollomi/utils.js#L63-L99","documentation":"FILE_NOT_FOUND is thrown by resolveImageInput when an image input is neither a URL (http/https/data:) nor an existing file on disk. resolveImageInput resolves the path and checks fs.existsSync before reading; any command accepting an --image input goes through this guard.","triggerScenarios":"Passing --image with a relative or absolute path that does not exist after path.resolve — e.g. a typo, a file deleted/moved after typing the command, or running from a different working directory than assumed.","commonSituations":"Running the CLI from a different cwd so relative paths break, typos in the filename, referencing files in another session's temp directory, or confusing an image URL with a local path (the guard accepts URLs, so this only fires for bad local paths).","solutions":["Verify the path with `ls <path>` and correct typos","Use an absolute path or run the command from the directory containing the file","Alternatively pass an http(s) or data: URL instead of a local file","If the file was moved/generated elsewhere, regenerate or copy it before running"],"exampleFix":"// before\nyollomi upscale --image ./imges/photo.png   # typo\n// FILE_NOT_FOUND\n// after\nyollomi upscale --image /home/me/images/photo.png","handlingStrategy":"validation","validationCode":"const resolved = path.resolve(input);\nif (!input.startsWith('http') && !input.startsWith('data:') && !fs.existsSync(resolved)) {\n  throw new Error(`Input image does not exist: ${resolved}`);\n}","typeGuard":"function isExistingPathOrUrl(input) {\n  return /^(https?:\\/\\/|data:)/.test(input) || fs.existsSync(path.resolve(input));\n}","tryCatchPattern":"try {\n  await upscale(page, { image: input });\n} catch (e) {\n  if (e.code === 'FILE_NOT_FOUND') console.error(`Bad path: ${e.message} — use an absolute path or URL`);\n  else throw e;\n}","preventionTips":["Use absolute paths or run from a known cwd","ls the path before scripting the call","Prefer http(s)/data: URLs for inputs generated in prior steps"],"tags":["cli","file-io","path","input-validation"],"backgroundTag":"file-not-found","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}