jackwener/OpenCLI · error · ArgumentError

weibo publish text exceeds 2000 characters

Error message

weibo publish text exceeds 2000 characters

What it means

validateText enforces Weibo's practical length ceiling: trimmed text longer than 2000 characters is rejected with an ArgumentError before any browser interaction. Weibo truncates or rejects overly long posts, so the CLI fails early.

Source

Thrown at clis/weibo/publish.js:47

const SUBMIT_POLL_MS = 500;
const SUBMIT_TIMEOUT_MS = 20_000;
const SUPPORTED_EXTENSIONS = new Set(['.jpg', '.jpeg', '.png', '.gif', '.webp']);

// Weibo PC UI selectors. The CSS-module hash drifts on every frontend
// rebuild (#1602), so match on the stable placeholder text and keep the
// legacy hash as a last-resort fallback. Callers pick the LAST visible
// match because the compose modal renders on top of the home-feed strip.
const TEXTAREA_SELECTORS = [
    'textarea[placeholder*="有什么新鲜事"]',
    'textarea[placeholder*="新鲜事"]',
    'textarea._input_13iqr_8',
];
const FILE_INPUT_SELECTOR = 'input[type="file"][class*="_file_"]';

function validateText(text) {
    const t = String(text ?? '').trim();
    if (!t) throw new ArgumentError('weibo publish text cannot be empty');
    if (t.length > 2000) throw new ArgumentError('weibo publish text exceeds 2000 characters');
    return t;
}

function validateImagePaths(raw) {
    if (!raw) return [];
    const paths = raw.split(',').map(s => s.trim()).filter(Boolean);
    if (paths.length > MAX_IMAGES) {
        throw new ArgumentError(`Too many images: ${paths.length} (max ${MAX_IMAGES})`);
    }
    return paths.map(p => {
        const absPath = path.resolve(p);
        const ext = path.extname(absPath).toLowerCase();
        if (!SUPPORTED_EXTENSIONS.has(ext)) {
            throw new ArgumentError(`Unsupported image format "${ext}". Supported: jpg, png, gif, webp`);
        }
        const stat = fs.statSync(absPath, { throwIfNoEntry: false });
        if (!stat || !stat.isFile()) {
            throw new ArgumentError(`Not a valid file: ${absPath}`);

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Shorten the text to 2000 characters or fewer before publishing
  2. Split the content into multiple posts
  3. Add a pre-flight length check (text.trim().length <= 2000) in your pipeline

Example fix

// before
weibo publish --text "$LONG_TEXT"
// after
TRIMMED=$(printf '%s' "$LONG_TEXT" | head -c 2000)
weibo publish --text "$TRIMMED"
Defensive patterns

Strategy: validation

Validate before calling

if (text.trim().length > 2000) {
  throw new Error('text exceeds 2000 characters: ' + text.trim().length);
}

Type guard

function isWithinLimit(v, max = 2000) {
  return typeof v === 'string' && v.trim().length <= max;
}

Try / catch

try {
  await cli.run(['weibo', 'publish', '--text', text]);
} catch (err) {
  if (/exceeds 2000 characters/.test(err.message)) {
    text = text.slice(0, 2000);
    // retry with truncated text
  } else throw err;
}

Prevention

When it happens

Trigger: Calling `weibo publish --text` with content whose trimmed length exceeds 2000 characters — e.g. pasting long articles or generated content.

Common situations: Scripting posts from files or LLM output without length checks; forgetting CJK-friendly trimming; concatenating content that pushes past the limit.

Related errors


AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29). Data as JSON: /api/errors/4de6c9c673739752. Report an issue: GitHub.