jackwener/OpenCLI · error · ArgumentError

weibo delete: URL must be a weibo.com or weibo.cn post URL

Error message

weibo delete: URL must be a weibo.com or weibo.cn post URL

What it means

When the id argument looks like a URL, its hostname must match WEIBO_HOST_RE, i.e. end with weibo.com or weibo.cn. URLs from other domains are rejected with ArgumentError so the command never deletes based on ids scraped from unrelated sites.

Solutions

  1. Open the short link in a browser and copy the final weibo.com/weibo.cn URL it redirects to
  2. Use the id directly from `weibo me`/`weibo post` output instead of a URL
  3. Ensure the domain is exactly weibo.com or weibo.cn (subdomains like www are fine; other brands are not)

Example fix

// before
weibo delete --id 'https://t.cn/A6bCdEf'
// after
weibo delete --id 'https://weibo.com/1234567890/AbCdEfGhI'
Defensive patterns

Strategy: validation

Validate before calling

function isWeiboPostUrl(u) {
  try { const url = new URL(u); return /(^|\.)weibo\.(com|cn)$/i.test(url.hostname); }
  catch { return false; }
}

Type guard

function isWeiboHost(hostname) {
  return /(^|\.)weibo\.(com|cn)$/i.test(hostname);
}

Try / catch

try {
  await cliDelete({ id: input });
} catch (err) {
  if (err instanceof ArgumentError && /weibo\.com or weibo\.cn post URL/.test(err.message)) {
    throw new Error('Resolve short links (t.cn) to the final weibo.com URL first');
  } else throw err;
}

Prevention

When it happens

Trigger: Passing a shortener link (t.cn, bit.ly), a mirror/aggregator URL, or a m.weibo.cn-adjacent domain not covered by the regex, or pasting the wrong link entirely (e.g. a Twitter/X URL).

Common situations: Users copying share links from third-party Weibo clients or shorteners, or confusing the post's t.cn short link (used in tweets) with the canonical weibo.com URL.

Related errors


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

Appendix: source

Thrown at clis/weibo/delete.js:24

import { requireObjectEvaluateResult, unwrapEvaluateResult } from './utils.js';

const WEIBO_HOST_RE = /(^|\.)weibo\.(com|cn)$/i;
const POST_ID_RE = /^[A-Za-z0-9]{4,32}$/;

function normalizePostId(raw) {
    const input = String(raw ?? '').trim();
    if (!input) {
        throw new ArgumentError('weibo delete: id cannot be empty');
    }

    let candidate = input;
    try {
        const url = new URL(input);
        if (url.protocol !== 'http:' && url.protocol !== 'https:') {
            throw new ArgumentError('weibo delete: URL must use http or https');
        }
        if (!WEIBO_HOST_RE.test(url.hostname)) {
            throw new ArgumentError('weibo delete: URL must be a weibo.com or weibo.cn post URL');
        }
        const parts = url.pathname.split('/').filter(Boolean);
        if (url.hostname.toLowerCase().endsWith('weibo.cn') && parts[0] === 'status') {
            candidate = parts[1] ?? '';
        } else {
            candidate = parts.at(-1) ?? '';
        }
    } catch (error) {
        if (error instanceof ArgumentError) throw error;
    }

    candidate = String(candidate ?? '').trim();
    if (!POST_ID_RE.test(candidate)) {
        throw new ArgumentError('weibo delete: id must be a numeric idstr, mblogid, or Weibo post URL');
    }
    return candidate;
}

View on GitHub (pinned to 49907e53dc)