jackwener/OpenCLI · error · ArgumentError

weibo delete: id must be a numeric idstr, mblogid, or Weibo

Error message

weibo delete: id must be a numeric idstr, mblogid, or Weibo post URL

What it means

After optional URL extraction (or if the input was not a URL), the final candidate id must match POST_ID_RE: 4-32 alphanumeric characters. This covers numeric idstr values and mblogid tokens. Anything else — mixed symbols, too short, too long, containing slashes/query leftovers — is rejected with ArgumentError.

Source

Thrown at clis/weibo/delete.js:38

        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;
}

cli({
    site: 'weibo',
    name: 'delete',
    access: 'write',
    description: 'Delete one of my Weibo posts by id',
    domain: 'weibo.com',
    strategy: Strategy.COOKIE,
    args: [
        {
            name: 'id',
            required: true,
            positional: true,
            help: 'Post ID (numeric idstr or mblogid from URL / weibo me / weibo post output)',
        },

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Copy the id exactly from `weibo me` or `weibo post` output (columns: id, mblogid)
  2. Use the numeric idstr from the weibo.com URL path, or the 8-10 char mblogid segment — only [A-Za-z0-9], 4-32 chars
  3. Strip any trailing '?', '/', or whitespace from the copied value

Example fix

// before
weibo delete --id 'AbCdEfGhI?from=feed'
// after
weibo delete --id 'AbCdEfGhI'
Defensive patterns

Strategy: validation

Validate before calling

const POST_ID_RE = /^[A-Za-z0-9]{4,32}$/;
function isValidWeiboPostId(id) {
  return typeof id === 'string' && POST_ID_RE.test(id.trim());
}
if (!isValidWeiboPostId(input)) throw new Error('id must be numeric idstr or mblogid');

Type guard

function isAlnumId(v) {
  return typeof v === 'string' && /^[A-Za-z0-9]{4,32}$/.test(v.trim());
}

Try / catch

try {
  await cliDelete({ id: input });
} catch (err) {
  if (err instanceof ArgumentError && /numeric idstr, mblogid, or Weibo post URL/.test(err.message)) {
    throw new Error('Strip query strings/punctuation; use id or mblogid from weibo post output');
  } else throw err;
}

Prevention

When it happens

Trigger: Passing the full post text, a username instead of a post id, an id with punctuation copied with trailing characters, a numeric id shorter than 4 chars, or a URL whose last path segment is empty or contains query strings.

Common situations: Copy-paste including '?from=...' fragments or brackets, using the display name instead of the post id, or truncating the mblogid when copying from terminal output.

Related errors


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