{"record":{"id":"c68c1dc057cb6758","repo":"jackwener/OpenCLI","slug":"bilibili-user-search-input","errorCode":null,"errorMessage":"bilibili user search: ${input}","messagePattern":"bilibili user search: (.+?)","errorType":"exception","errorClass":"EmptyResultError","httpStatus":null,"severity":"warning","filePath":"clis/bilibili/utils.js","lineNumber":301,"sourceCode":"    const payload = await apiGet(page, '/x/web-interface/wbi/search/type', {\n        params: { search_type: 'bili_user', keyword: input },\n        signed: true,\n    });\n    if (!payload || typeof payload !== 'object' || Array.isArray(payload) || !payload.data || typeof payload.data !== 'object' || Array.isArray(payload.data) || !Object.hasOwn(payload.data, 'result')) {\n        throw new CommandExecutionError(`Bilibili user search returned malformed result for ${input}`);\n    }\n    const results = payload.data.result;\n    if (!Array.isArray(results)) {\n        throw new CommandExecutionError(`Bilibili user search returned malformed result for ${input}`);\n    }\n    if (results.length > 0) {\n        const mid = String(results[0]?.mid ?? '').trim();\n        if (!mid) {\n            throw new CommandExecutionError(`Bilibili user search returned malformed mid for ${input}`);\n        }\n        return mid;\n    }\n    throw new EmptyResultError(`bilibili user search: ${input}`, 'User may not exist or username may have changed.');\n}\n","sourceCodeStart":283,"sourceCodeEnd":303,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/bilibili/utils.js#L283-L303","documentation":"resolveUid throws EmptyResultError('bilibili user search: ${input}') when the Bilibili user search succeeded structurally but returned zero results — meaning the lookup produced no user. It is a distinct, catchable signal that the username does not map to any account.","triggerScenarios":"Searching a username that no longer exists, was changed, or is not indexed by Bilibili search; calling mid/uid/resolveTargetMid with a typo'd or renamed username.","commonSituations":"User renamed their Bilibili account; typo in the username; searching for a deactivated/banned account; user set privacy settings hiding them from search.","solutions":["Verify the username spelling and current Bilibili profile page","Resolve by UID (number) instead of username via the uid command","Catch EmptyResultError specifically and prompt the user to update the target username","Use Bilibili's web UI search to confirm the account still exists under that name"],"exampleFix":"// before\nconst mid = await resolveTargetMid(args.user);\n// after\ntry { const mid = await resolveTargetMid(args.user); }\ncatch (e) { if (e instanceof EmptyResultError) console.error(`No Bilibili user found for \"${args.user}\" — check the username or use --uid`); else throw e; }","handlingStrategy":"try-catch","validationCode":"// sanity-check the username client-side before lookup\nif (!/^[\\w\\-.\\u4e00-\\u9fa5]+$/.test(username)) throw new Error('suspicious username format');","typeGuard":"null","tryCatchPattern":"try { const mid = await resolveUid(name); }\ncatch (e) {\n  if (e instanceof EmptyResultError) { console.warn(`No user \"${name}\" — may not exist or username changed`); }\n  else throw e;\n}","preventionTips":["Catch EmptyResultError separately from CommandExecutionError","Confirm usernames against bilibili.com before automation","Store and reuse numeric mids instead of re-resolving names","Handle renamed/deleted accounts gracefully in scripts"],"tags":["empty-result","user-lookup","bilibili"],"backgroundTag":"empty-search-result","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}