{"record":{"id":"41ae36520683d337","repo":"jackwener/OpenCLI","slug":"too-many-images-imagepaths-length-max-max-i","errorCode":null,"errorMessage":"Too many images: ${imagePaths.length} (max ${MAX_IMAGES})","messagePattern":"Too many images: (.+?) \\(max (.+?)\\)","errorType":"validation","errorClass":"ArgumentError","httpStatus":null,"severity":"error","filePath":"clis/xiaohongshu/publish.js","lineNumber":1208,"sourceCode":"            : [];\n        const isDraft = Boolean(kwargs.draft);\n        const cardText = kwargs['card-text'] ? String(kwargs['card-text']) : '';\n        const cards = cardText\n            ? cardText.split(CARD_TEXT_DELIM).map((s) => s.trim()).filter(Boolean)\n            : [];\n        const cardStyle = kwargs['card-style'] ? String(kwargs['card-style']).trim() : '';\n        const isTextImage = cards.length > 0;\n        // ── Validate inputs ────────────────────────────────────────────────────────\n        if (!title)\n            throw new ArgumentError('--title is required');\n        if (title.length > MAX_TITLE_LEN)\n            throw new ArgumentError(`Title is ${title.length} chars — must be ≤ ${MAX_TITLE_LEN}`);\n        if (!content)\n            throw new ArgumentError('Positional argument <content> is required');\n        if (!isTextImage && imagePaths.length === 0)\n            throw new ArgumentError('Provide --card-text (text-image mode) or --images (upload mode); neither was given.');\n        if (imagePaths.length > MAX_IMAGES)\n            throw new ArgumentError(`Too many images: ${imagePaths.length} (max ${MAX_IMAGES})`);\n        // The editor-page image input (text-image append) rejects gif.\n        if (isTextImage && imagePaths.some((p) => path.extname(p).toLowerCase() === '.gif'))\n            throw new ArgumentError('文字配图模式追加的图片不支持 .gif（编辑器图片入口只接受 jpg/jpeg/png/webp）');\n        // Validate image paths before navigating (fast-fail on bad paths / unsupported formats)\n        const absImagePaths = validateImagePaths(imagePaths);\n        // ── Step 1: Navigate to publish page ──────────────────────────────────────\n        await page.goto(PUBLISH_URL);\n        await page.wait({ time: 3 });\n        // Verify we landed on the creator site (not redirected to login)\n        const pageUrl = await page.evaluate('() => location.href');\n        if (!pageUrl.includes('creator.xiaohongshu.com')) {\n            throw new Error('Redirected away from creator center — session may have expired. ' +\n                'Re-capture browser login via: opencli xiaohongshu creator-profile');\n        }\n        // ── Step 2: Select 图文 (image+text) note type if tabs are present ─────────\n        const tabResult = await selectImageTextTab(page);\n        const surface = await waitForPublishSurfaceState(page, tabResult?.ok ? 5_000 : 2_000);\n        if (surface.state === 'video_surface') {","sourceCodeStart":1190,"sourceCodeEnd":1226,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/xiaohongshu/publish.js#L1190-L1226","documentation":"ArgumentError thrown when more than MAX_IMAGES (9) image paths are supplied, matching XHS's per-note image limit. The check runs before any browser automation so failures are fast.","triggerScenarios":"Upload mode with --images containing more than 9 comma-separated paths, or text-image mode where the accompanying images list exceeds 9 entries.","commonSituations":"Batch-exporting many photos and passing them all at once; building the --images list from a glob/directory listing that yields >9 files; forgetting XHS's hard cap of 9 images per note.","solutions":["Trim the --images list to 9 or fewer paths","Split into multiple notes if you have more than 9 images","Generate the list programmatically with a limit: files.slice(0, 9).join(',')"],"exampleFix":"// before\n--images \"$(ls photos/*.jpg | tr '\\n' ',')\"   # may exceed 9\n// after\n--images \"$(ls photos/*.jpg | head -9 | tr '\\n' ',')\"","handlingStrategy":"validation","validationCode":"const paths = imagesFlag.split(',').map(s => s.trim()).filter(Boolean);\nif (paths.length > 9) throw new Error(`Only 9 images allowed, got ${paths.length}`);","typeGuard":"function withinImageLimit(paths) {\n  return Array.isArray(paths) && paths.length >= 1 && paths.length <= 9;\n}","tryCatchPattern":"try {\n  await publish(page, { images: imagesFlag, ...rest });\n} catch (e) {\n  if (String(e.message).startsWith('Too many images')) {\n    const trimmed = imagesFlag.split(',').slice(0, 9).join(',');\n    // retry with first 9 images\n  } else throw e;\n}","preventionTips":["Cap glob/directory-derived image lists at 9","Split large sets into multiple notes","Remember XHS's hard 9-image per-note limit"],"tags":["validation","cli-arguments","limit","xiaohongshu"],"backgroundTag":"input-limit-exceeded","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}