{"record":{"id":"faec220b0a711b02","repo":"jackwener/OpenCLI","slug":"image-file-not-found-abspath-faec22","errorCode":null,"errorMessage":"Image file not found: ${absPath}","messagePattern":"Image file not found: (.+?)","errorType":"validation","errorClass":"ArgumentError","httpStatus":null,"severity":"error","filePath":"clis/xiaohongshu/publish.js","lineNumber":129,"sourceCode":"    if (\n        value\n        && typeof value === 'object'\n        && typeof value.session === 'string'\n        && Object.prototype.hasOwnProperty.call(value, 'data')\n    ) {\n        return value.data;\n    }\n    return value;\n}\n/**\n * Validate image paths: check existence and extension.\n * Returns resolved absolute paths.\n */\nfunction validateImagePaths(filePaths) {\n    return filePaths.map((filePath) => {\n        const absPath = path.resolve(filePath);\n        if (!fs.existsSync(absPath))\n            throw new ArgumentError(`Image file not found: ${absPath}`);\n        const ext = path.extname(absPath).toLowerCase();\n        if (!SUPPORTED_EXTENSIONS[ext]) {\n            throw new ArgumentError(`Unsupported image format \"${ext}\". Supported: jpg, png, gif, webp`);\n        }\n        return absPath;\n    });\n}\n/** CSS selector for image-accepting file inputs. */\nconst IMAGE_INPUT_SELECTOR = 'input[type=\"file\"][accept*=\"image\"],'\n    + 'input[type=\"file\"][accept*=\".jpg\"],'\n    + 'input[type=\"file\"][accept*=\".jpeg\"],'\n    + 'input[type=\"file\"][accept*=\".png\"],'\n    + 'input[type=\"file\"][accept*=\".gif\"],'\n    + 'input[type=\"file\"][accept*=\".webp\"]';\n/**\n * Upload images via CDP DOM.setFileInputFiles — Chrome reads files directly\n * from the local filesystem, avoiding base64 payload size limits.\n *","sourceCodeStart":111,"sourceCodeEnd":147,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/xiaohongshu/publish.js#L111-L147","documentation":"ArgumentError from validateImagePaths in the publish CLI: path.resolve was applied to the given file path and fs.existsSync found no file at the resolved absolute location. The publish flow aborts before opening the browser because there is nothing to upload.","triggerScenarios":"Passing a non-existent or misspelled image path to the publish command's image arguments; running from a different working directory than assumed so a relative path resolves elsewhere; file deleted between planning and publishing.","commonSituations":"Typos in path or extension; relative paths like './img.png' when cwd differs; paths with unexpanded '~' or shell variables; case-sensitive filesystems where the filename casing is wrong.","solutions":["Check the exact path exists: ls the resolved absolute path printed in the error message.","Expand '~' and environment variables in the path or pass an absolute path.","Run the command from the directory you expect, or fix the relative path.","Verify the file was not moved/deleted before publish."],"exampleFix":"// before\nawait xhs.publish({ images: ['~/Pictures/note.png'] });\n// after\nconst os = require('os');\nconst p = '~/Pictures/note.png'.replace(/^~/, os.homedir());\nif (!require('fs').existsSync(p)) throw new Error('missing image: ' + p);\nawait xhs.publish({ images: [p] });","handlingStrategy":"validation","validationCode":"const fs = require('fs'), path = require('path');\nconst abs = images.map(p => path.resolve(p.replace(/^~/, require('os').homedir())));\nconst missing = abs.filter(p => !fs.existsSync(p));\nif (missing.length) throw new Error('Missing image files: ' + missing.join(', '));","typeGuard":"function imageFileExists(p) {\n  return typeof p === 'string' && p.length > 0 && fs.existsSync(path.resolve(p));\n}","tryCatchPattern":"try {\n  await xhs.publish({ images });\n} catch (err) {\n  if (err.message.startsWith('Image file not found:')) {\n    console.error('Fix path:', err.message);\n  } else throw err;\n}","preventionTips":["Always pass absolute paths to publish","Expand ~ and env vars in paths before calling","List/verify image files right before publishing","Avoid renaming/moving files between selection and publish"],"tags":["filesystem","argument-error","file-not-found","xiaohongshu"],"backgroundTag":"image-file-not-found","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}