{"record":{"id":"901d1644bd0c3877","repo":"jackwener/OpenCLI","slug":"failed-to-fetch-douyin-comments-for-video-awemei","errorCode":null,"errorMessage":"Failed to fetch Douyin comments for video ${awemeId}: ${error instanceof Error ? error.message : String(error)}","messagePattern":"Failed to fetch Douyin comments for video (.+?): (.+?)","errorType":"exception","errorClass":"CommandExecutionError","httpStatus":null,"severity":"error","filePath":"clis/douyin/user-videos.js","lineNumber":53,"sourceCode":"    return Math.min(DEFAULT_COMMENT_LIMIT, Math.max(1, Math.round(numeric)));\n}\nasync function mapInBatches(items, concurrency, mapper) {\n    const results = [];\n    for (let index = 0; index < items.length; index += concurrency) {\n        const chunk = items.slice(index, index + concurrency);\n        results.push(...(await Promise.all(chunk.map(mapper))));\n    }\n    return results;\n}\nasync function fetchTopComments(page, awemeId, count) {\n    try {\n        return await fetchDouyinComments(page, awemeId, count);\n    }\n    catch (error) {\n        if (error instanceof CliError) {\n            throw error;\n        }\n        throw new CommandExecutionError(`Failed to fetch Douyin comments for video ${awemeId}: ${error instanceof Error ? error.message : String(error)}`);\n    }\n}\ncli({\n    site: 'douyin',\n    name: 'user-videos',\n    access: 'read',\n    description: '获取指定用户的视频列表（含下载地址和热门评论）',\n    domain: 'www.douyin.com',\n    strategy: Strategy.COOKIE,\n    args: [\n        { name: 'sec_uid', type: 'string', required: true, positional: true, help: '用户 sec_uid（个人主页 URL 末尾部分，也可直接传整条主页 URL）' },\n        { name: 'limit', type: 'int', default: 20, help: '获取数量（最大 20）' },\n        { name: 'with_comments', type: 'bool', default: true, help: '包含热门评论（默认: true）' },\n        { name: 'comment_limit', type: 'int', default: 10, help: '每个视频获取多少条评论（最大 10）' },\n    ],\n    columns: ['index', 'aweme_id', 'title', 'duration', 'digg_count', 'play_url', 'top_comments'],\n    func: async (page, kwargs) => {\n        const secUid = normalizeSecUid(kwargs.sec_uid);","sourceCodeStart":35,"sourceCodeEnd":71,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/douyin/user-videos.js#L35-L71","documentation":"A CommandExecutionError wrapping any non-CliError failure raised while fetching top comments for a video during douyin user-videos. fetchTopComments rethrows CliError subclasses untouched, but converts unexpected exceptions (browser page errors, API failures, timeouts) into a single message prefixed with the awemeId so batch processing can surface which video failed.","triggerScenarios":"Calling `douyin user-videos --with-comments` when fetchDouyinComments throws a non-CliError for one of the video's awemeIds — e.g. the comment popup never loads, the page DOM changed, or the browser tab crashed mid-batch.","commonSituations":"Douyin DOM/API change breaking the comment scraper; rate limiting or a network hiccup while mapInBatches hits videos concurrently; expired login state causing comment requests to return error pages instead of data.","solutions":["Read the wrapped error.message (appended after the awemeId) to find the underlying cause.","Re-run the command with --with-comments disabled (or --comment-limit lowered) to confirm the videos themselves still list fine.","Reduce --comment-limit / concurrency pressure and retry after a pause if rate limited.","Refresh the Douyin session (re-run auth) if the underlying message suggests auth or empty responses.","If persistent, update the CLI package — the comment fetcher may lag a Douyin DOM change."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n  const { videos } = await run('douyin user-videos', { sec_uid, with_comments: true });\n} catch (e) {\n  if (e.name === 'CommandExecutionError' && /comments for video/.test(e.message)) {\n    console.warn(`comment fetch failed (${e.message}); retrying without comments`);\n    return run('douyin user-videos', { sec_uid, with_comments: false });\n  }\n  throw e;\n}","preventionTips":["Lower --comment-limit to reduce per-video work and rate-limit pressure.","Keep the Douyin session valid; refresh auth if failures cluster.","Prefer with_comments: false for bulk runs; fetch comments selectively."],"tags":["command-execution","douyin","scraping","network"],"backgroundTag":"scrape-failed","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}