{"record":{"id":"0addc105f7da27a7","repo":"jackwener/OpenCLI","slug":"not-a-valid-file-abspath-0addc1","errorCode":null,"errorMessage":"Not a valid file: ${absPath}","messagePattern":"Not a valid file: (.+?)","errorType":"validation","errorClass":"ArgumentError","httpStatus":null,"severity":"error","filePath":"clis/weibo/publish.js","lineNumber":65,"sourceCode":"    if (t.length > 2000) throw new ArgumentError('weibo publish text exceeds 2000 characters');\n    return t;\n}\n\nfunction validateImagePaths(raw) {\n    if (!raw) return [];\n    const paths = raw.split(',').map(s => s.trim()).filter(Boolean);\n    if (paths.length > MAX_IMAGES) {\n        throw new ArgumentError(`Too many images: ${paths.length} (max ${MAX_IMAGES})`);\n    }\n    return paths.map(p => {\n        const absPath = path.resolve(p);\n        const ext = path.extname(absPath).toLowerCase();\n        if (!SUPPORTED_EXTENSIONS.has(ext)) {\n            throw new ArgumentError(`Unsupported image format \"${ext}\". Supported: jpg, png, gif, webp`);\n        }\n        const stat = fs.statSync(absPath, { throwIfNoEntry: false });\n        if (!stat || !stat.isFile()) {\n            throw new ArgumentError(`Not a valid file: ${absPath}`);\n        }\n        return absPath;\n    });\n}\n\ncli({\n    site: 'weibo',\n    name: 'publish',\n    access: 'write',\n    description: 'Publish a new Weibo post immediately',\n    domain: 'weibo.com',\n    strategy: Strategy.UI,\n    browser: true,\n    args: [\n        {\n            name: 'text',\n            type: 'string',\n            required: true,","sourceCodeStart":47,"sourceCodeEnd":83,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/weibo/publish.js#L47-L83","documentation":"After the extension check, validateImagePaths stats each resolved path with fs.statSync(..., { throwIfNoEntry: false }); if the file does not exist or is not a regular file (directory, symlink to nothing, device), an ArgumentError with the absolute path is thrown.","triggerScenarios":"--images entries pointing to missing files, directories, or broken symlinks; typos in paths; relative paths resolving against an unexpected working directory.","commonSituations":"Running the CLI from a different cwd than the script assumed; cleanup jobs deleting temp screenshots before publish; passing a directory of images instead of individual files.","solutions":["Verify each path exists and is a file (`ls -l` / fs.statSync) before invoking","Use absolute paths to avoid cwd-dependent resolution","Fix typos and remove directories or dead symlinks from the list"],"exampleFix":"// before\n--images ./shots\n// after\n--images /abs/path/shots/shot1.png,/abs/path/shots/shot2.png","handlingStrategy":"validation","validationCode":"const fs = require('fs');\nfor (const p of paths) {\n  const abs = require('path').resolve(p);\n  const st = fs.statSync(abs, { throwIfNoEntry: false });\n  if (!st || !st.isFile()) throw new Error(`not a file: ${abs}`);\n}","typeGuard":null,"tryCatchPattern":"try {\n  await cli.run(['weibo', 'publish', '--text', text, '--images', images]);\n} catch (err) {\n  if (/Not a valid file/.test(err.message)) {\n    console.error('Missing path or directory passed:', err.message);\n  } else throw err;\n}","preventionTips":["Use absolute paths to avoid cwd surprises","stat every file before invoking","Exclude directories and dead symlinks from lists"],"tags":["validation","argument-error","filesystem"],"backgroundTag":"file-not-found","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}