jackwener/OpenCLI · error · ArgumentError

Cannot follow yourself

Error message

Cannot follow yourself

What it means

After resolving the target mid, the command fetches your own UID via getSelfUid and refuses to follow yourself (mid === self), throwing this ArgumentError — the follow API would reject it anyway and the state is meaningless.

Source

Thrown at clis/bilibili/follow.js:66

    domain: 'www.bilibili.com',
    strategy: Strategy.COOKIE,
    args: [
        {
            name: 'target',
            required: true,
            positional: true,
            help: '目标 UID / 用户名 / space.bilibili.com 链接',
        },
    ],
    columns: ['mid', 'name', 'status', 'url'],
    func: async (page, kwargs) => {
        if (!page) {
            throw new CommandExecutionError('Browser session required for bilibili follow');
        }
        const mid = await resolveTargetMid(page, kwargs.target);
        const self = await getSelfUid(page);
        if (mid === self) {
            throw new ArgumentError('Cannot follow yourself');
        }
        const attribute = await fetchRelationAttribute(page, mid);
        const url = `https://space.bilibili.com/${mid}`;
        if (attribute === 2 || attribute === 6) {
            return [{ mid, name: '', status: 'already-following', url }];
        }
        if (attribute === 128) {
            throw new CommandExecutionError(
                `Bilibili user ${mid} is blocked; unblock first before following.`,
            );
        }
        // act=1 follow, act=2 unfollow. re_src=11 is the community-standard
        // "web" source value used by third-party libs (bilibili-api-python etc.);
        // omitting it makes the modify API reject with a vague code.
        const payload = await apiPost(page, '/x/relation/modify', {
            params: { fid: mid, act: 1, re_src: 11 },
        });
        requireOkPayload(payload, 'relation modify');

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Choose a different target account.
  2. Filter your own mid out of any batch target list before running.
  3. Verify which account the browser is logged in as if you did not expect a self-follow.

Example fix

// before
for (const uid of uids) await follow(uid);
// after
const self = await getSelfUid(page);
for (const uid of uids.filter((u) => u !== self)) await follow(uid);
Defensive patterns

Strategy: validation

Validate before calling

const self = await getSelfUid(page);
const mid = await resolveTargetMid(page, target);
if (mid === self) throw new Error(`refusing self-follow: ${mid}`);

Type guard

function isNotSelf(mid, selfUid) {
  return String(mid) !== String(selfUid);
}

Try / catch

try {
  await follow(target);
} catch (e) {
  if (e instanceof ArgumentError && e.message === 'Cannot follow yourself') {
    console.warn('target equals the logged-in account; skipping');
    return;
  }
  throw e;
}

Prevention

When it happens

Trigger: Passing your own UID/username/space URL as the follow target, or getSelfUid resolving to the same account you typed.

Common situations: Testing the CLI against your own account, looping over a list of UIDs that includes yours, reusing a config where the target was set to your own profile.

Related errors


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