jackwener/OpenCLI · error · ArgumentError

weibo user-posts id cannot be empty

Error message

weibo user-posts id cannot be empty

What it means

ArgumentError thrown by readRequiredId when the `id` argument to `weibo user-posts` is empty, whitespace-only, null, or undefined. The command requires a user id (or profile identifier) to know whose posts to fetch, and refuses to run with a blank value.

Source

Thrown at clis/weibo/user-posts.js:15

/**
 * Weibo user-posts — list posts from a user within an optional date range.
 */
import { cli, Strategy } from '@jackwener/opencli/registry';
import { ArgumentError, AuthRequiredError, CommandExecutionError, EmptyResultError } from '@jackwener/opencli/errors';
import { unwrapEvaluateResult } from './utils.js';

const MAX_LIMIT = 100;
const DEFAULT_LIMIT = 20;
const DATE_RE = /^\d{4}-\d{2}-\d{2}$/;

function readRequiredId(raw) {
    const value = String(raw ?? '').trim();
    if (!value) {
        throw new ArgumentError('weibo user-posts id cannot be empty');
    }
    return value;
}

function readLimit(raw) {
    const value = raw === undefined || raw === null || raw === '' ? DEFAULT_LIMIT : Number(raw);
    if (!Number.isInteger(value) || value < 1 || value > MAX_LIMIT) {
        throw new ArgumentError(`weibo user-posts limit must be an integer between 1 and ${MAX_LIMIT}`);
    }
    return value;
}

function readDate(raw, name) {
    if (raw === undefined || raw === null || raw === '') return null;
    const value = String(raw).trim();
    if (!DATE_RE.test(value)) {
        throw new ArgumentError(`weibo user-posts ${name} must use YYYY-MM-DD`);
    }

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Pass a non-empty user id: `weibo user-posts <id>`
  2. Verify the upstream variable actually contains the id before invoking (echo it or add a shell check)
  3. Look up the correct id from the user's weibo.com profile URL

Example fix

// before
weibo user-posts "$WEIBO_ID"
// after
[ -n "${WEIBO_ID:-}" ] || { echo 'WEIBO_ID is empty'; exit 1; }
weibo user-posts "$WEIBO_ID"
Defensive patterns

Strategy: validation

Validate before calling

const id = String(process.env.WEIBO_ID ?? '').trim();
if (!id) {
    throw new Error('weibo user-posts requires a non-empty id');
}
await weiboUserPosts({ id });

Type guard

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

Try / catch

try {
    await weiboUserPosts({ id });
} catch (err) {
    if (err instanceof ArgumentError && String(err.message).includes('id cannot be empty')) {
        console.error('Provide a Weibo user id, e.g. `weibo user-posts <id>`');
    } else throw err;
}

Prevention

When it happens

Trigger: Running `weibo user-posts ""` or `weibo user-posts` with no positional id, or passing a value that is only whitespace (String(raw ?? '').trim() yields '').

Common situations: Shell variable holding the id was unset (`weibo user-posts "$UID_VAR"` with empty var); scripting pipelines where an upstream extraction produced an empty string; forgetting the positional argument entirely.

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/255d09886ca24f37. Report an issue: GitHub.