{"record":{"id":"64a7fa0e4e383bb6","repo":"jackwener/OpenCLI","slug":"positional-argument-content-is-required","errorCode":null,"errorMessage":"Positional argument <content> is required","messagePattern":"Positional argument <content> is required","errorType":"validation","errorClass":"ArgumentError","httpStatus":null,"severity":"error","filePath":"clis/xiaohongshu/publish.js","lineNumber":1204,"sourceCode":"            ? String(kwargs.images).split(',').map((s) => s.trim()).filter(Boolean)\n            : [];\n        const topics = kwargs.topics\n            ? String(kwargs.topics).split(',').map((s) => s.trim()).filter(Boolean)\n            : [];\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        }","sourceCodeStart":1186,"sourceCodeEnd":1222,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/xiaohongshu/publish.js#L1186-L1222","documentation":"ArgumentError thrown when the trimmed positional <content> argument is empty. Every publish (text-image or upload mode) requires body content, so the CLI fails fast before any browser automation runs.","triggerScenarios":"Running the publish command without the positional content argument, or with an empty/whitespace-only string, so `String(kwargs.content ?? '').trim()` is empty.","commonSituations":"Forgetting the positional argument entirely; quoting mistakes so the shell swallows the content; passing content via a flag by mistake instead of positionally; content consisting only of whitespace/newlines.","solutions":["Pass the body text as the positional argument: publish.js --title \"标题\" \"正文内容\"","Quote multi-word content so the shell passes it as one argument","Verify the content is not only whitespace after trimming"],"exampleFix":"// before\nnode publish.js --title \"标题\" --card-text \"a|b\"   # content missing\n// after\nnode publish.js --title \"标题\" --card-text \"a|b\" \"这是正文内容\"","handlingStrategy":"validation","validationCode":"const content = String(rawContent ?? '').trim();\nif (!content) throw new Error('Positional <content> is required');","typeGuard":"function hasContent(c) {\n  return typeof c === 'string' && c.trim().length > 0;\n}","tryCatchPattern":"try {\n  await publish(page, { title, content, ...rest });\n} catch (e) {\n  if (String(e.message).includes('<content> is required')) {\n    console.error('Pass body text as the positional argument, quoted');\n  }\n  throw e;\n}","preventionTips":["Always quote the positional content argument","Don't rely on unquoted variables that may expand to nothing","Validate inputs in wrapper scripts first"],"tags":["validation","cli-arguments","xiaohongshu"],"backgroundTag":"missing-required-argument","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}