{"record":{"id":"8c7783499abca7ac","repo":"jackwener/OpenCLI","slug":"cannot-resolve-bilibili-target-from-input-trimm-8c7783","errorCode":null,"errorMessage":"Cannot resolve Bilibili target from input: ${trimmed}","messagePattern":"Cannot resolve Bilibili target from input: (.+?)","errorType":"validation","errorClass":"ArgumentError","httpStatus":null,"severity":"error","filePath":"clis/bilibili/unfollow.js","lineNumber":28,"sourceCode":"import { apiPost, getSelfUid, requireOkPayload, resolveUid } from './utils.js';\n\nasync function resolveTargetMid(page, raw) {\n    const trimmed = String(raw ?? '').trim();\n    if (!trimmed) {\n        throw new ArgumentError('bilibili unfollow target cannot be empty');\n    }\n    if (/^(?:https?:\\/\\/)?space\\.bilibili\\.com\\//i.test(trimmed)) {\n        const mid = parseSpaceMidUrl(trimmed);\n        if (!mid) {\n            throw new ArgumentError('bilibili unfollow target must be a valid space.bilibili.com/<uid> URL');\n        }\n        return mid;\n    }\n    try {\n        return await resolveUid(page, trimmed);\n    } catch (error) {\n        if (error instanceof EmptyResultError) throw error;\n        throw new ArgumentError(\n            `Cannot resolve Bilibili target from input: ${trimmed}`,\n            error instanceof Error ? error.message : String(error),\n        );\n    }\n}\n\ncli({\n    site: 'bilibili',\n    name: 'unfollow',\n    access: 'write',\n    description: '取消关注 B站用户（官方 API，需登录）',\n    domain: 'www.bilibili.com',\n    strategy: Strategy.COOKIE,\n    args: [\n        {\n            name: 'target',\n            required: true,\n            positional: true,","sourceCodeStart":10,"sourceCodeEnd":46,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/bilibili/unfollow.js#L10-L46","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Pass an exact numeric uid or a full space.bilibili.com/<uid> URL instead of a fuzzy username","Check the cause message (second ArgumentError argument) to see why resolveUid failed (login required, empty result, network)","Verify you are logged into bilibili in the browser session (unfollow requires an authenticated session anyway)","Search the uid on space.bilibili.com manually to confirm the account exists"],"exampleFix":"// before\nawait bilibiliUnfollow({ target: '某UP主昵称' });\n// after\nawait bilibiliUnfollow({ target: '1234567' });","handlingStrategy":"try-catch","validationCode":"if (!/^\\d+$/.test(String(target ?? '').trim()) && !isValidSpaceUrl(target) && typeof target !== 'string') {\n  throw new Error('target must be a uid string, username, or space URL');\n}","typeGuard":"function looksResolvable(v) {\n  const t = String(v ?? '').trim();\n  return /^\\d+$/.test(t) || /^[A-Za-z0-9_-]+$/.test(t) || isSpaceUrlWithUid(t);\n}","tryCatchPattern":"try {\n  await bilibiliUnfollow({ target });\n} catch (err) {\n  if (err instanceof ArgumentError && err.message.startsWith('Cannot resolve Bilibili target')) {\n    console.error(`Could not resolve '${target}': ${err.cause ?? err.message}. Try the numeric uid.`);\n  } else throw err;\n}","preventionTips":["Use numeric uids, not nicknames — display names are not unique identifiers","Confirm the account exists by opening space.bilibili.com/<uid> first","Ensure the browser session is logged in so resolution works","Log the wrapped cause message to distinguish empty-result vs network failures"],"tags":["argument-validation","bilibili","resolution-failure"],"backgroundTag":"target-resolution-failed","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T17:17:51.833Z"}