{"record":{"id":"a184428ce52ebaf9","repo":"jackwener/OpenCLI","slug":"weibo-publish-text-cannot-be-empty","errorCode":null,"errorMessage":"weibo publish text cannot be empty","messagePattern":"weibo publish text cannot be empty","errorType":"validation","errorClass":"ArgumentError","httpStatus":null,"severity":"error","filePath":"clis/weibo/publish.js","lineNumber":46,"sourceCode":"const COMPOSE_TIMEOUT_MS = 10_000;\nconst SUBMIT_POLL_MS = 500;\nconst SUBMIT_TIMEOUT_MS = 20_000;\nconst SUPPORTED_EXTENSIONS = new Set(['.jpg', '.jpeg', '.png', '.gif', '.webp']);\n\n// Weibo PC UI selectors. The CSS-module hash drifts on every frontend\n// rebuild (#1602), so match on the stable placeholder text and keep the\n// legacy hash as a last-resort fallback. Callers pick the LAST visible\n// match because the compose modal renders on top of the home-feed strip.\nconst 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()) {","sourceCodeStart":28,"sourceCodeEnd":64,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/weibo/publish.js#L28-L64","documentation":"validateText rejects publish requests whose `text` option is missing, empty, or only whitespace. Weibo does not accept an empty post body, so the CLI fails fast with an ArgumentError before touching the browser.","triggerScenarios":"Calling `weibo publish` without `--text`, with `--text \"\"` or `--text \"   \"`, or when a shell variable holding the text expands to empty.","commonSituations":"CI scripts where the post body comes from an env var or file that is empty; forgetting the --text flag; quoting bugs that swallow the argument.","solutions":["Pass non-empty text via --text \"your message\"","Check that any variable/file feeding the text is non-empty before invoking","If posting images only is intended, note this CLI still requires non-empty text"],"exampleFix":"// before\nweibo publish --text \"$MSG\"\n// after\n[ -n \"$MSG\" ] || { echo 'MSG is empty'; exit 1; }\nweibo publish --text \"$MSG\"","handlingStrategy":"validation","validationCode":"const t = (text ?? '').trim();\nif (!t) throw new Error('text is required and cannot be empty');","typeGuard":"function isValidText(v) {\n  return typeof v === 'string' && v.trim().length > 0;\n}","tryCatchPattern":"try {\n  await cli.run(['weibo', 'publish', '--text', text]);\n} catch (err) {\n  if (/text cannot be empty/.test(err.message)) {\n    console.error('Provide non-empty --text');\n  } else throw err;\n}","preventionTips":["Always pass --text explicitly","Validate shell variables are non-empty before interpolation","Remember image-only posts are not supported by this CLI"],"tags":["validation","argument-error","weibo"],"backgroundTag":"missing-required-argument","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}