{"record":{"id":"2767e1727f9073d7","repo":"jackwener/OpenCLI","slug":"bilibili-creator-comparison-returned-duplicate-row","errorCode":null,"errorMessage":"Bilibili creator comparison returned duplicate rows for ${bvid}","messagePattern":"Bilibili creator comparison returned duplicate rows for (.+?)","errorType":"exception","errorClass":"CommandExecutionError","httpStatus":null,"severity":"error","filePath":"clis/bilibili/creator-stats.js","lineNumber":102,"sourceCode":"            throw new TimeoutError('Bilibili creator comparison', FETCH_TIMEOUT_SECONDS);\n        }\n        if (/HTTP\\s+(401|403)|登录|passport|\\/login\\b/i.test(detail)) {\n            throw new AuthRequiredError('member.bilibili.com', `Bilibili creator-center login is required: ${detail}`);\n        }\n        throw new CommandExecutionError(`Bilibili creator comparison request failed: ${detail}`);\n    }\n}\n\nfunction selectTarget(list, bvid) {\n    const matches = [];\n    for (const item of list) {\n        if (!isRecord(item) || typeof item.bvid !== 'string' || !/^BV[0-9A-Za-z]{10}$/.test(item.bvid)) {\n            throw new CommandExecutionError('Bilibili creator comparison returned a malformed manuscript row');\n        }\n        if (item.bvid === bvid) matches.push(item);\n    }\n    if (matches.length > 1) {\n        throw new CommandExecutionError(`Bilibili creator comparison returned duplicate rows for ${bvid}`);\n    }\n    if (matches.length === 0) {\n        throw new EmptyResultError(\n            `bilibili creator-stats ${bvid}`,\n            'The manuscript was not present in the latest 100 creator analytics rows; it may be older, not owned by this account, or not analyzed yet.',\n        );\n    }\n    const target = matches[0];\n    if (!isRecord(target.stat)) {\n        throw new CommandExecutionError(`Bilibili creator comparison returned malformed stat data for ${bvid}`);\n    }\n    return target;\n}\n\nfunction metricValue(target, definition) {\n    const source = definition.source === 'target' ? target : target.stat;\n    if (!Object.prototype.hasOwnProperty.call(source, definition.key)) {\n        throw new CommandExecutionError(`Bilibili creator comparison omitted metric ${definition.key}`);","sourceCodeStart":84,"sourceCodeEnd":120,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/bilibili/creator-stats.js#L84-L120","documentation":"After whitelisting each row, selectTarget collects rows whose bvid equals the requested bvid. If more than one row matches, the result would be ambiguous (which stat block is authoritative?), so the library throws this CommandExecutionError naming the duplicated bvid rather than picking an arbitrary row.","triggerScenarios":"payload.data.list contains two or more entries with the same bvid as the requested manuscript — e.g. Bilibili returning the video once per analytics dimension or paging overlap within the size=100 window.","commonSituations":"Bilibili server returning duplicated rows in the comparison payload; endpoint behavior change duplicating entries across pages/dimensions; retried fetches concatenating results in an intermediate layer.","solutions":["Log the full list and confirm the duplication is server-side (not caused by your own merging code)","Update selectTarget to deduplicate by bvid (e.g. keep the first row) if duplicates are benign","Retry later — if it is a transient Bilibili-side glitch, a fresh fetch may return clean rows","Report/track the endpoint anomaly since the endpoint is undocumented and unstable"],"exampleFix":"// before: throw on duplicates\nif (matches.length > 1) {\n    throw new CommandExecutionError(`...duplicate rows for ${bvid}`);\n}\n\n// after: tolerate duplicates deterministically\nconst target = matches[0];","handlingStrategy":"fallback","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n  const rows = await runCommand();\n} catch (e) {\n  if (/duplicate rows for/.test(e.message)) {\n    // retry once; if persistent, deduplicate by bvid (first occurrence) upstream\n  } else throw e;\n}","preventionTips":["Deduplicate list rows by bvid before analysis if the endpoint is known to duplicate","Retry on first occurrence — duplication may be a transient server glitch","Record the raw payload when this fires to confirm whether it is server-side"],"tags":["bilibili","data-integrity","duplicate-data","api-contract"],"backgroundTag":"duplicate-records-in-response","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}