{"record":{"id":"284eef8b2b8adaeb","repo":"jackwener/OpenCLI","slug":"createlist-returned-name-json-stringify-list-nam","errorCode":null,"errorMessage":"CreateList returned name ${JSON.stringify(list.name)}, expected ${JSON.stringify(expectedName)}.","messagePattern":"CreateList returned name (.+?), expected (.+?)\\.","errorType":"exception","errorClass":"CommandExecutionError","httpStatus":null,"severity":"error","filePath":"clis/twitter/list-create.js","lineNumber":70,"sourceCode":"        throw new CommandExecutionError(`CreateList returned malformed JSON payload. Body: ${String(result.bodyText || '').slice(0, 300)}`);\n    }\n    const list = result.bodyJson?.data?.list;\n    if (!list || typeof list !== 'object') {\n        const errors = result.bodyJson?.errors;\n        if (Array.isArray(errors) && errors.length > 0) {\n            throw new CommandExecutionError(`CreateList failed: ${errors[0].message || JSON.stringify(errors[0])}`);\n        }\n        throw new CommandExecutionError(`CreateList returned no list payload. Body: ${String(result.bodyText || '').slice(0, 300)}`);\n    }\n    const id = String(list.id_str || list.id || '');\n    if (!/^\\d+$/.test(id)) {\n        throw new CommandExecutionError('CreateList returned a list payload without a numeric list id.');\n    }\n    if (typeof list.name !== 'string' || !list.name.trim()) {\n        throw new CommandExecutionError('CreateList returned a list payload without a list name.');\n    }\n    if (list.name.trim() !== expectedName) {\n        throw new CommandExecutionError(`CreateList returned name ${JSON.stringify(list.name)}, expected ${JSON.stringify(expectedName)}.`);\n    }\n    const modeValue = typeof list.mode === 'string' ? list.mode : '';\n    if (!modeValue) {\n        throw new CommandExecutionError('CreateList returned a list payload without list mode.');\n    }\n    const mode = /private/i.test(modeValue) ? 'private' : 'public';\n    if (mode !== expectedMode) {\n        throw new CommandExecutionError(`CreateList returned mode ${mode}, expected ${expectedMode}.`);\n    }\n    return { createdList: list, listId: id, listMode: mode };\n}\n\nexport function buildListCreateRow({ result, name, description, mode }) {\n    const { createdList, listId, listMode } = requireCreateListResult(result, name, mode);\n    return {\n        id: listId,\n        name: createdList.name,\n        description: typeof createdList.description === 'string' ? createdList.description : description,","sourceCodeStart":52,"sourceCodeEnd":88,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/twitter/list-create.js#L52-L88","documentation":"requireCreateListResult checks that the created list's echoed `name` matches the name the user asked for. It throws when Twitter's CreateList response returns a trimmed name different from the expected one. This prevents the CLI from claiming success for a list that was created with a different label than requested.","triggerScenarios":"list.name.trim() !== expectedName after a CreateList call — e.g. the name was altered by Twitter (length truncation, entity encoding), or the caller passed the wrong expectedName (empty string vs the actual --name).","commonSituations":"List names exceeding Twitter's 25-character limit get truncated; HTML-escaping of characters like & in names; calling buildListCreateRow with a name different from the kwargs actually sent.","solutions":["Compare the requested name against Twitter's 25-character list name limit and shorten it","Check for special characters that Twitter may escape or normalize, and avoid them","Verify the expectedName passed to requireCreateListResult matches the name actually sent in the CreateList variables","Re-run the command; if persistent, inspect the response payload for the actual name"],"exampleFix":"// before\nconst name = 'My very long list name exceeding limits';\n// after\nconst name = args.name.slice(0, 25); // respect Twitter's max list name length","handlingStrategy":"validation","validationCode":"const requested = name.trim();\nif (requested.length > 25) throw new Error('Twitter list names max 25 characters');\nif (requested !== expectedName?.trim()) throw new Error('expectedName does not match requested name');","typeGuard":"function nameMatches(list, expected) {\n  return typeof list?.name === 'string' && list.name.trim() === String(expected).trim();\n}","tryCatchPattern":"try {\n  const row = buildListCreateRow({ result, name, description, mode });\n} catch (e) {\n  if (/CreateList returned name/.test(e.message)) console.error('Name mismatch:', e.message, '— check truncation/escaping');\n  else throw e;\n}","preventionTips":["Keep list names within Twitter's 25-char limit","Avoid characters Twitter may escape or normalize","Pass the exact same trimmed name to the API and to buildListCreateRow"],"tags":["api-response","name-mismatch","validation"],"backgroundTag":"schema-validation-failed","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}