{"record":{"id":"1ce8b28ef4e7fd51","repo":"jackwener/OpenCLI","slug":"bilibili-user-search-returned-malformed-mid-for","errorCode":null,"errorMessage":"Bilibili user search returned malformed mid for @${name}","messagePattern":"Bilibili user search returned malformed mid for @(.+?)","errorType":"exception","errorClass":"CommandExecutionError","httpStatus":null,"severity":"error","filePath":"clis/bilibili/comment.js","lineNumber":68,"sourceCode":"        // Resolve bvid → aid (the reply API addresses videos by aid, as `oid`)\n        const view = await apiGet(page, '/x/web-interface/view', { params: { bvid } });\n        const viewData = requireOkPayload(view, 'view');\n        const oid = viewData?.aid;\n        if (!oid)\n            throw new CommandExecutionError(`Cannot resolve aid for bvid: ${bvid}`);\n        // Resolve @username mentions to uids. Bilibili only turns \"@name\" into a real\n        // mention — one that notifies the mentioned user — when the request carries\n        // at_name_to_mid; a plain-text \"@name\" is otherwise inert and notifies nobody.\n        /** @type {Record<string, number>} */\n        const atNameToMid = {};\n        for (const match of message.matchAll(/@([^\\s@]+)/g)) {\n            const name = match[1];\n            if (name in atNameToMid)\n                continue;\n            try {\n                const mid = Number(await resolveUid(page, name));\n                if (!Number.isInteger(mid) || mid <= 0) {\n                    throw new CommandExecutionError(`Bilibili user search returned malformed mid for @${name}`);\n                }\n                atNameToMid[name] = mid;\n            }\n            catch (error) {\n                if (!(error instanceof EmptyResultError)) {\n                    throw error;\n                }\n                // Unresolvable @name (typo, or not a user) — leave it as plain text.\n            }\n        }\n        // For a reply, Bilibili needs both `root` (top-level comment) and `parent`.\n        // Replying to a top-level comment means root === parent.\n        const params = {\n            oid,\n            type: 1,\n            message,\n            plat: 1,\n            ...(parent != null","sourceCodeStart":50,"sourceCodeEnd":86,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/bilibili/comment.js#L50-L86","documentation":"@mentions are resolved to user ids (mid) via resolveUid (user search). If the search returns a value that is not a positive integer, the CLI throws CommandExecutionError; EmptyResultError (user not found) is tolerated and skipped, but other errors propagate.","triggerScenarios":"A --message containing @name where the search API returns a malformed/non-numeric mid for that username — duplicate or renamed usernames, search API returning unexpected payload, or resolveUid returning empty string.","commonSituations":"Mentioning a username that no longer exists or was renamed; usernames with special characters confusing search; rate-limited or anti-bot response degrading the search payload.","solutions":["Verify the @username exists via bilibili search and matches exactly","Remove or correct the @mention in --message","Retry after a short delay if the search API was rate-limiting","Confirm resolveUid works standalone for the problem username"],"exampleFix":"// before\n--message \"thanks @old_name\"\n// after\n--message \"thanks @current_name\"  // verified via search","handlingStrategy":"fallback","validationCode":"const users = await searchUser(name);\nif (!users.length) throw new Error(`@${name} not found; remove the mention`);","typeGuard":"const isValidMid = (v) => Number.isInteger(Number(v)) && Number(v) > 0;","tryCatchPattern":"try { await commentCmd(); } catch (e) { if (String(e.message).includes('malformed mid')) { console.error('Drop or fix the @mention and retry'); } else throw e; }","preventionTips":["Mention only usernames verified via search","Avoid usernames with unusual characters","Throttle mention resolution to avoid rate limits","Treat EmptyResultError as 'skip mention' behavior"],"tags":["api","mention","response-parsing"],"backgroundTag":"api-response-missing-field","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T17:17:51.833Z"}