{"record":{"id":"71d401c66b80202d","repo":"jackwener/OpenCLI","slug":"too-many-images-paths-length-max-max-images-71d401","errorCode":null,"errorMessage":"Too many images: ${paths.length} (max ${MAX_IMAGES})","messagePattern":"Too many images: (.+?) \\(max (.+?)\\)","errorType":"validation","errorClass":"ArgumentError","httpStatus":null,"severity":"error","filePath":"clis/weibo/publish.js","lineNumber":55,"sourceCode":"const TEXTAREA_SELECTORS = [\n    'textarea[placeholder*=\"有什么新鲜事\"]',\n    'textarea[placeholder*=\"新鲜事\"]',\n    'textarea._input_13iqr_8',\n];\nconst FILE_INPUT_SELECTOR = 'input[type=\"file\"][class*=\"_file_\"]';\n\nfunction validateText(text) {\n    const t = String(text ?? '').trim();\n    if (!t) throw new ArgumentError('weibo publish text cannot be empty');\n    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',","sourceCodeStart":37,"sourceCodeEnd":73,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/weibo/publish.js#L37-L73","documentation":"validateImagePaths caps attachments at MAX_IMAGES; supplying more comma-separated image paths than allowed throws an ArgumentError before any upload begins.","triggerScenarios":"Calling `weibo publish --images` with a comma-separated list containing more entries than MAX_IMAGES (defined in clis/weibo/publish.js).","commonSituations":"Globbing a directory of screenshots into the flag; reusing a list built for another tool with a higher limit; accidental duplicate paths.","solutions":["Reduce the image list to at most MAX_IMAGES entries","Publish in multiple batches","Deduplicate the path list before passing it"],"exampleFix":"// before\n--images img1.jpg,img2.jpg,img3.jpg,img4.jpg,img5.jpg,img6.jpg\n// after (if MAX_IMAGES is 4)\nweibo publish --text \"...\" --images img1.jpg,img2.jpg,img3.jpg,img4.jpg","handlingStrategy":"validation","validationCode":"const MAX_IMAGES = 4; // match clis/weibo/publish.js\nconst paths = images.split(',').map(s => s.trim()).filter(Boolean);\nif (paths.length > MAX_IMAGES) throw new Error(`max ${MAX_IMAGES} images`);","typeGuard":null,"tryCatchPattern":"try {\n  await cli.run(['weibo', 'publish', '--text', text, '--images', images]);\n} catch (err) {\n  if (/Too many images/.test(err.message)) {\n    console.error('Split the upload into batches');\n  } else throw err;\n}","preventionTips":["Count comma-separated entries before invoking","Deduplicate path lists","Batch large uploads into multiple calls"],"tags":["validation","argument-error","image-upload"],"backgroundTag":"too-many-items","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}