{"record":{"id":"5eb05e184f43c435","repo":"jackwener/OpenCLI","slug":"douyin-stats-awemeid","errorCode":null,"errorMessage":"douyin stats ${awemeId}","messagePattern":"douyin stats (.+?)","errorType":"exception","errorClass":"EmptyResultError","httpStatus":null,"severity":"warning","filePath":"clis/douyin/stats.js","lineNumber":63,"sourceCode":"        let cursor;\n\n        for (let hop = 0; hop < MAX_HOPS; hop++) {\n            const params = new URLSearchParams({\n                count: String(PAGE_SIZE),\n                order_by: '1',\n                fields: 'metrics,review,visibility',\n                need_cooperation: 'true',\n                need_long_article: 'true',\n            });\n            if (cursor !== undefined)\n                params.set('max_cursor', String(cursor));\n\n            const response = await browserFetch(page, 'GET', `${ITEM_LIST_URL}?${params.toString()}`);\n            const item = (response.items ?? []).find((candidate) => sameAwemeId(candidate?.id, awemeId));\n            if (item) {\n                const metrics = item.metrics;\n                if (!metrics || typeof metrics !== 'object' || Array.isArray(metrics)) {\n                    throw new EmptyResultError(`douyin stats ${awemeId}`, 'The work exists, but creator metrics are unavailable');\n                }\n                return Object.entries(metrics).map(([metric, value]) => ({ metric, value }));\n            }\n\n            const nextCursor = response.max_cursor;\n            if (!response.has_more || nextCursor === undefined || nextCursor === null\n                || (cursor !== undefined && String(nextCursor) === String(cursor))) {\n                break;\n            }\n            cursor = nextCursor;\n        }\n\n        throw new EmptyResultError(`douyin stats ${awemeId}`, 'The work was not found in the logged-in creator account');\n    },\n});\n","sourceCodeStart":45,"sourceCodeEnd":79,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/douyin/stats.js#L45-L79","documentation":"EmptyResultError (scope `douyin stats <awemeId>`) thrown when the matched creator item exists in the item/list response but its `metrics` field is missing, not an object, or an array. The work exists in the creator account, but the 26-field creator metrics payload wasn't returned.","triggerScenarios":"The item/list API returns an item whose metrics key is null/absent — typically when the work is under review, deleted-but-cached, a non-video type slipping through, or the account lacks deep-metrics permission for that work.","commonSituations":"Querying a work still in review or recently published before metrics are computed; works outside the logged-in creator account surfaced via cooperation list; Douyin API field changes; non-video works (long articles) with empty metric sets.","solutions":["Verify in creator.douyin.com that the work is published and its data panel shows metrics.","Wait and retry if the work was just published (metrics compute asynchronously).","Confirm the aweme_id belongs to the logged-in creator account's own works.","Handle EmptyResultError gracefully and fall back to public/detail metrics if creator metrics are unavailable."],"exampleFix":"// before\nconst rows = await run(['douyin', 'stats', awemeId]);\n// after\ntry {\n  const rows = await run(['douyin', 'stats', awemeId]);\n} catch (e) {\n  if (e.name === 'EmptyResultError' && /metrics are unavailable/.test(e.message ?? '')) {\n    return fallbackPublicMetrics(awemeId); // detail endpoint\n  }\n  throw e;\n}","handlingStrategy":"fallback","validationCode":null,"typeGuard":"function hasMetrics(item) {\n  return item != null && typeof item.metrics === 'object' && item.metrics !== null && !Array.isArray(item.metrics);\n}","tryCatchPattern":"try {\n  rows = await run(['douyin', 'stats', awemeId]);\n} catch (e) {\n  if (e.name === 'EmptyResultError' && /creator metrics are unavailable/.test(e.message ?? '')) {\n    return publicDetailMetrics(awemeId); // fallback source\n  }\n  throw e;\n}","preventionTips":["Only query works owned by the logged-in creator account with visible metrics panels.","Delay queries until after publishing/review completes so metrics exist.","Cache which aweme_ids reliably return metrics to avoid repeated misses."],"tags":["empty-results","api-response","douyin","metrics"],"backgroundTag":"missing-api-field","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}