jackwener/OpenCLI · error · ArgumentError

Cannot resolve Bilibili target from input: ${trimmed}

Error message

Cannot resolve Bilibili target from input: ${trimmed}

What it means

resolveTargetMid's catch-all: when the target is neither a space.bilibili.com URL nor resolvable via resolveUid (which resolves uid/username through the bilibili page), the original error is wrapped in an ArgumentError 'Cannot resolve Bilibili target from input: <trimmed>'. EmptyResultError is rethrown unchanged. This tells you the input could not be turned into a Bilibili mid at all.

Source

Thrown at clis/bilibili/unfollow.js:28

import { apiPost, getSelfUid, requireOkPayload, resolveUid } from './utils.js';

async function resolveTargetMid(page, raw) {
    const trimmed = String(raw ?? '').trim();
    if (!trimmed) {
        throw new ArgumentError('bilibili unfollow target cannot be empty');
    }
    if (/^(?:https?:\/\/)?space\.bilibili\.com\//i.test(trimmed)) {
        const mid = parseSpaceMidUrl(trimmed);
        if (!mid) {
            throw new ArgumentError('bilibili unfollow 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: 'unfollow',
    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. Pass an exact numeric uid or a full space.bilibili.com/<uid> URL instead of a fuzzy username
  2. Check the cause message (second ArgumentError argument) to see why resolveUid failed (login required, empty result, network)
  3. Verify you are logged into bilibili in the browser session (unfollow requires an authenticated session anyway)
  4. Search the uid on space.bilibili.com manually to confirm the account exists

Example fix

// before
await bilibiliUnfollow({ target: '某UP主昵称' });
// after
await bilibiliUnfollow({ target: '1234567' });
Defensive patterns

Strategy: try-catch

Validate before calling

if (!/^\d+$/.test(String(target ?? '').trim()) && !isValidSpaceUrl(target) && typeof target !== 'string') {
  throw new Error('target must be a uid string, username, or space URL');
}

Type guard

function looksResolvable(v) {
  const t = String(v ?? '').trim();
  return /^\d+$/.test(t) || /^[A-Za-z0-9_-]+$/.test(t) || isSpaceUrlWithUid(t);
}

Try / catch

try {
  await bilibiliUnfollow({ target });
} catch (err) {
  if (err instanceof ArgumentError && err.message.startsWith('Cannot resolve Bilibili target')) {
    console.error(`Could not resolve '${target}': ${err.cause ?? err.message}. Try the numeric uid.`);
  } else throw err;
}

Prevention

When it happens

Trigger: Calling bilibili unfollow with a target that is a non-existent username, a uid that resolveUid fails to find, or an unrecognized string (e.g. random text, a nickname that doesn't match any user), causing resolveUid to reject with a non-EmptyResultError error.

Common situations: Typos in a username; passing a display name (nickname) instead of the unique username/uid; bilibili session not logged in so the search page yields no match; network/anti-bot failures during resolution that aren't empty-result cases.

Related errors


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