{"record":{"id":"dbffd6d8bca7f5df","repo":"jackwener/OpenCLI","slug":"failed-to-add-username-to-list-listid-inva","errorCode":null,"errorMessage":"Failed to add @${username} to list ${listId}: invalid member_count in response","messagePattern":"Failed to add @(.+?) to list (.+?): invalid member_count in response","errorType":"exception","errorClass":"CommandExecutionError","httpStatus":null,"severity":"error","filePath":"clis/twitter/list-add-core.js","lineNumber":76,"sourceCode":"        );\n    }\n\n    // X often returns a partial GraphQL error on `default_banner_media_results`\n    // even on successful mutations. Treat only missing main data or non-decode\n    // GraphQL errors as command failures.\n    const hasMemberCount = addResult.mc !== null && addResult.mc !== undefined;\n    const fatalErrors = fatalGraphqlErrors(addResult.errors);\n    if (!hasMemberCount && fatalErrors.length) {\n        const msg = fatalErrors.map((e) => e.message || JSON.stringify(e)).join('; ');\n        throw new CommandExecutionError(`Failed to add @${username} to list ${listId}: ${msg.slice(0, 300)}`);\n    }\n    if (!hasMemberCount) {\n        throw new CommandExecutionError(`Failed to add @${username} to list ${listId}: no member_count in response`);\n    }\n\n    const memberCountAfter = Number(addResult.mc);\n    if (!Number.isFinite(memberCountAfter)) {\n        throw new CommandExecutionError(`Failed to add @${username} to list ${listId}: invalid member_count in response`);\n    }\n\n    if (memberCountAfter < memberCountBefore) {\n        throw new CommandExecutionError(\n            `Failed to add @${username} to list ${listId}: member_count decreased unexpectedly (${memberCountBefore} → ${memberCountAfter})`\n        );\n    }\n\n    const countIncreased = memberCountAfter > memberCountBefore;\n    const noop = !countIncreased;\n    if (noop && addResult.isMember !== true) {\n        throw new CommandExecutionError(\n            `Failed to add @${username} to list ${listId}: member_count unchanged and membership was not confirmed`\n        );\n    }\n    const verifiedBy = `member_count ${memberCountBefore} → ${memberCountAfter}`;\n    return {\n        listId,","sourceCodeStart":58,"sourceCodeEnd":94,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/twitter/list-add-core.js#L58-L94","documentation":"A CommandExecutionError from buildListAddMemberRow thrown when the member_count in the response exists but Number(addResult.mc) is not finite (NaN). This guards against malformed or non-numeric count values that would make post-mutation verification meaningless.","triggerScenarios":"X returned a member_count value that cannot be coerced to a finite number — e.g. a string like 'unknown', null-adjacent placeholder, or a corrupted/HTML response parsed into the mc field.","commonSituations":"Response scraping picking up markup instead of the count during X UI changes; schema drift producing unexpected types at addResult.mc.","solutions":["Retry the command — a transient bad response often succeeds on a second attempt.","Update the library to match X's current response schema.","Refresh session cookies to avoid bot-check/degraded responses.","Enable raw-response logging to inspect what value mc held, and report persistent occurrences."],"exampleFix":"// before\n{ mc: \"unknown\" }  // Number('unknown') === NaN -> throws\n// after: retry with a fresh session, expecting numeric mc\n{ mc: 42 }","handlingStrategy":"retry","validationCode":"null","typeGuard":"function hasNumericMemberCount(r) {\n  return typeof r?.mc === 'number' && Number.isFinite(r.mc) || (typeof r?.mc === 'string' && /^\\d+$/.test(r.mc));\n}","tryCatchPattern":"try {\n  return await listAddUser(page, { listId, username });\n} catch (e) {\n  if (/invalid member_count/.test(e.message)) {\n    await sleep(5000);\n    return listAddUser(page, { listId, username }); // one retry, often transient\n  }\n  throw e;\n}","preventionTips":["Retry once after a short wait — malformed counts are often transient.","Update the library when X changes its response schema.","Use a fresh session to avoid bot-check HTML being parsed into fields.","Inspect raw responses if the error persists."],"tags":["twitter","graphql","malformed-response","cli"],"backgroundTag":"invalid-response-field-type","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}