jackwener/OpenCLI · error · ArgumentError

weibo delete: id cannot be empty

Error message

weibo delete: id cannot be empty

What it means

normalizePostId validates the id argument for the weibo delete command. If the raw input trims to an empty string, there is nothing to normalize or resolve, so it throws ArgumentError immediately before any URL parsing.

Source

Thrown at clis/weibo/delete.js:14

/**
 * Weibo delete — remove a single post owned by the logged-in user.
 */
import { cli, Strategy } from '@jackwener/opencli/registry';
import { ArgumentError, AuthRequiredError, CommandExecutionError, EmptyResultError } from '@jackwener/opencli/errors';
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) {

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Pass a valid id: numeric idstr, mblogid, or a weibo.com/cn post URL, e.g. weibo delete --id 5012345678901
  2. Check the shell variable holding the id is actually set (echo "$POST_ID") before invoking the CLI
  3. Copy the id from `weibo me` or `weibo post` output columns (id / mblogid) rather than retyping it

Example fix

// before
weibo delete --id "$POST_ID"
// after
: "${POST_ID:?POST_ID is not set}"
weibo delete --id "$POST_ID"
Defensive patterns

Strategy: validation

Validate before calling

function isValidDeleteArg(id) {
  return typeof id === 'string' && id.trim().length > 0;
}
if (!isValidDeleteArg(process.env.POST_ID)) throw new Error('POST_ID is empty');

Type guard

function isNonEmptyString(v) {
  return typeof v === 'string' && v.trim().length > 0;
}

Try / catch

try {
  await cliDelete({ id: rawId });
} catch (err) {
  if (err instanceof ArgumentError && /id cannot be empty/.test(err.message)) {
    throw new Error('Provide --id: numeric idstr, mblogid, or weibo post URL');
  } else throw err;
}

Prevention

When it happens

Trigger: Calling `weibo delete` with no --id value, an --id of "" or whitespace, or passing kwargs.id as null/undefined from a script that failed to capture the id from a previous command's output.

Common situations: Shell variable interpolation producing an empty string (e.g. $POST_ID unset), copy-paste losing the id, or a wrapper script forwarding a null id from upstream JSON.

Understand the failure class

Background: "missing required argument" and "the following required arguments were not provided": what required-argument errors mean and how to fix them — this error's family across 20 libraries.

Related errors


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