{"record":{"id":"a2c80c7fb534f19f","repo":"jackwener/OpenCLI","slug":"title-is-required-a2c80c","errorCode":null,"errorMessage":"--title is required","messagePattern":"--title is required","errorType":"validation","errorClass":"ArgumentError","httpStatus":null,"severity":"error","filePath":"clis/xiaohongshu/publish.js","lineNumber":1200,"sourceCode":"            throw new Error('Browser page required');\n        const title = String(kwargs.title ?? '').trim();\n        const content = String(kwargs.content ?? '').trim();\n        const imagePaths = kwargs.images\n            ? 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');","sourceCodeStart":1182,"sourceCodeEnd":1218,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/xiaohongshu/publish.js#L1182-L1218","documentation":"ArgumentError thrown during input validation when the trimmed --title value is empty. The publish command requires a non-empty title string; an empty title would fail on the XHS editor anyway, so the CLI fails fast before navigating to the publish page.","triggerScenarios":"Running the publish command with no --title flag, with --title \"\" or --title \"   \" (whitespace only), so `String(kwargs.title ?? '').trim()` yields an empty string.","commonSituations":"Forgetting the --title flag; shell quoting issues that drop the value (e.g. --title \"$UNSET_VAR\"); passing the title positionally by mistake; title containing only whitespace/emoji stripped by trim.","solutions":["Pass a non-empty --title \"你的标题\" argument","Check shell variable expansion — echo the value before running to confirm it is not empty","Remember the title must also be ≤ 20 chars (MAX_TITLE_LEN) to pass the next check"],"exampleFix":"// before\nnode publish.js --title \"\" --content \"正文\"\n// after\nnode publish.js --title \"我的笔记标题\" --content \"正文\"","handlingStrategy":"validation","validationCode":"const title = String(process.argvTitle ?? '').trim();\nif (!title) throw new Error('--title is required');","typeGuard":"function isValidTitle(t) {\n  return typeof t === 'string' && t.trim().length > 0;\n}","tryCatchPattern":"try {\n  await publish(page, { title, ...rest });\n} catch (e) {\n  if (e.name === 'ArgumentError' && e.message.includes('--title')) {\n    console.error('Supply a non-empty --title, e.g. --title \"我的标题\"');\n  }\n  throw e;\n}","preventionTips":["Echo shell variables before interpolation to catch empty expansions","Quote --title values","Trim and validate inputs in wrapper scripts before invoking the CLI"],"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"}