{"record":{"id":"08b342ae30f20924","repo":"jackwener/OpenCLI","slug":"cannot-unfollow-yourself","errorCode":null,"errorMessage":"Cannot unfollow yourself","messagePattern":"Cannot unfollow yourself","errorType":"validation","errorClass":"ArgumentError","httpStatus":null,"severity":"error","filePath":"clis/bilibili/unfollow.js","lineNumber":58,"sourceCode":"    domain: 'www.bilibili.com',\n    strategy: Strategy.COOKIE,\n    args: [\n        {\n            name: 'target',\n            required: true,\n            positional: true,\n            help: '目标 UID / 用户名 / space.bilibili.com 链接',\n        },\n    ],\n    columns: ['mid', 'name', 'status', 'url'],\n    func: async (page, kwargs) => {\n        if (!page) {\n            throw new CommandExecutionError('Browser session required for bilibili unfollow');\n        }\n        const mid = await resolveTargetMid(page, kwargs.target);\n        const self = await getSelfUid(page);\n        if (mid === self) {\n            throw new ArgumentError('Cannot unfollow yourself');\n        }\n        const attribute = await fetchRelationAttribute(page, mid);\n        const url = `https://space.bilibili.com/${mid}`;\n        // attribute 2=following, 6=mutual. Anything else means the viewer isn't\n        // currently following — skip the POST and return idempotent status.\n        if (attribute !== 2 && attribute !== 6) {\n            return [{ mid, name: '', status: 'not-following', url }];\n        }\n        const payload = await apiPost(page, '/x/relation/modify', {\n            params: { fid: mid, act: 2, re_src: 11 },\n        });\n        requireOkPayload(payload, 'relation modify');\n        await waitForRelation(page, mid, (nextAttribute) => nextAttribute !== 2 && nextAttribute !== 6, 'not following');\n        return [{ mid, name: '', status: 'unfollowed', url }];\n    },\n});\n","sourceCodeStart":40,"sourceCodeEnd":75,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/bilibili/unfollow.js#L40-L75","documentation":"After resolving the target mid, the command compares it with the logged-in user's own uid (getSelfUid) and throws ArgumentError 'Cannot unfollow yourself' if they match. Unfollowing yourself is not a valid bilibili relation operation, so it is blocked up front.","triggerScenarios":"Running `bilibili unfollow --target <your own uid or space URL>` where the resolved mid equals the authenticated user's uid.","commonSituations":"Testing the command against your own account; a script iterating over a follow list that accidentally includes the self account; pasting your own profile URL as a placeholder target.","solutions":["Pass a different target — the uid/space URL of the UP主 you actually want to unfollow","Filter your own uid out of any batch list before calling unfollow","If you intended to inspect your own follows, use the follow-list command instead"],"exampleFix":"// before\nconst target = await getSelfUid(page);\nawait bilibiliUnfollow({ target });\n// after\nif (target === selfUid) return; // skip self\nawait bilibiliUnfollow({ target });","handlingStrategy":"validation","validationCode":"const selfUid = await getSelfUid(page);\nconst targetUid = String(target).match(/space\\.bilibili\\.com\\/(\\d+)/i)?.[1] ?? (/^\\d+$/.test(target) ? target : null);\nif (targetUid != null && targetUid === selfUid) {\n  throw new Error(`Refusing to unfollow yourself (${selfUid})`);\n}","typeGuard":"function isNotSelf(targetUid, selfUid) {\n  return String(targetUid) !== String(selfUid);\n}","tryCatchPattern":"try {\n  await bilibiliUnfollow({ target });\n} catch (err) {\n  if (err instanceof ArgumentError && err.message === 'Cannot unfollow yourself') {\n    console.warn('Skipping self account in batch');\n  } else throw err;\n}","preventionTips":["Filter your own uid out of batch unfollow lists using getSelfUid","Never use your own profile URL as a test target","In batch scripts, log-and-skip when target equals self instead of aborting"],"tags":["argument-validation","bilibili","self-action"],"backgroundTag":"invalid-target-self-reference","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}