jackwener/OpenCLI · error · ArgumentError

Cannot resolve Bilibili target from input: ${trimmed}

Error message

Cannot resolve Bilibili target from input: ${trimmed}

What it means

Fallback path: when the target is neither empty nor a space URL, resolveTargetMid tries resolveUid (username/keyword search). If that fails for any reason other than EmptyResultError, the original error is wrapped in this ArgumentError with the raw input echoed, so callers see which input failed and why.

Source

Thrown at clis/bilibili/follow.js:36

 * and likely return nothing.
 */
async function resolveTargetMid(page, raw) {
    const trimmed = String(raw ?? '').trim();
    if (!trimmed) {
        throw new ArgumentError('bilibili follow target cannot be empty');
    }
    if (/^(?:https?:\/\/)?space\.bilibili\.com\//i.test(trimmed)) {
        const mid = parseSpaceMidUrl(trimmed);
        if (!mid) {
            throw new ArgumentError('bilibili follow target must be a valid space.bilibili.com/<uid> URL');
        }
        return mid;
    }
    try {
        return await resolveUid(page, trimmed);
    } catch (error) {
        if (error instanceof EmptyResultError) throw error;
        throw new ArgumentError(
            `Cannot resolve Bilibili target from input: ${trimmed}`,
            error instanceof Error ? error.message : String(error),
        );
    }
}

cli({
    site: 'bilibili',
    name: 'follow',
    access: 'write',
    description: '关注 B站用户(官方 API,需登录)',
    domain: 'www.bilibili.com',
    strategy: Strategy.COOKIE,
    args: [
        {
            name: 'target',
            required: true,
            positional: true,

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Use the numeric UID directly — it is stable and skips search entirely.
  2. Re-check the username on bilibili.com; copy it again without surrounding whitespace.
  3. If resolveUid failed due to throttling, wait and retry; the cause is in the wrapped second argument.

Example fix

// before
bilibili follow --target '旧昵称'
// after
bilibili follow --target 9469745
Defensive patterns

Strategy: fallback

Validate before calling

if (!/^\d+$/.test(target) && /^(?:https?:\/\/)?space\.bilibili\.com\//i.test(target) === false) {
  console.warn(`target '${target}' will go through user search; prefer a numeric uid`);
}

Type guard

function isNumericUid(s) {
  return /^\d+$/.test(String(s).trim());
}

Try / catch

try {
  return await resolveTargetMid(page, raw);
} catch (e) {
  if (e instanceof ArgumentError && e.message.startsWith('Cannot resolve Bilibili target')) {
    console.error(`Could not resolve '${raw}': ${e.cause ?? ''}. Try the numeric uid.`);
    return null;
  }
  throw e;
}

Prevention

When it happens

Trigger: Passing a username/nickname that no longer exists, a renamed account, input with invisible characters, or resolveUid failing due to risk control / search API errors.

Common situations: User changed their Bilibili nickname, targeting a deactivated account, or search endpoint throttled (-412) making the lookup fail.

Related errors


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