jackwener/OpenCLI · error · CommandExecutionError

CreateList returned name ${JSON.stringify(list.name)}, expec

Error message

CreateList returned name ${JSON.stringify(list.name)}, expected ${JSON.stringify(expectedName)}.

What it means

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.

Source

Thrown at clis/twitter/list-create.js:70

        throw new CommandExecutionError(`CreateList returned malformed JSON payload. Body: ${String(result.bodyText || '').slice(0, 300)}`);
    }
    const list = result.bodyJson?.data?.list;
    if (!list || typeof list !== 'object') {
        const errors = result.bodyJson?.errors;
        if (Array.isArray(errors) && errors.length > 0) {
            throw new CommandExecutionError(`CreateList failed: ${errors[0].message || JSON.stringify(errors[0])}`);
        }
        throw new CommandExecutionError(`CreateList returned no list payload. Body: ${String(result.bodyText || '').slice(0, 300)}`);
    }
    const id = String(list.id_str || list.id || '');
    if (!/^\d+$/.test(id)) {
        throw new CommandExecutionError('CreateList returned a list payload without a numeric list id.');
    }
    if (typeof list.name !== 'string' || !list.name.trim()) {
        throw new CommandExecutionError('CreateList returned a list payload without a list name.');
    }
    if (list.name.trim() !== expectedName) {
        throw new CommandExecutionError(`CreateList returned name ${JSON.stringify(list.name)}, expected ${JSON.stringify(expectedName)}.`);
    }
    const modeValue = typeof list.mode === 'string' ? list.mode : '';
    if (!modeValue) {
        throw new CommandExecutionError('CreateList returned a list payload without list mode.');
    }
    const mode = /private/i.test(modeValue) ? 'private' : 'public';
    if (mode !== expectedMode) {
        throw new CommandExecutionError(`CreateList returned mode ${mode}, expected ${expectedMode}.`);
    }
    return { createdList: list, listId: id, listMode: mode };
}

export function buildListCreateRow({ result, name, description, mode }) {
    const { createdList, listId, listMode } = requireCreateListResult(result, name, mode);
    return {
        id: listId,
        name: createdList.name,
        description: typeof createdList.description === 'string' ? createdList.description : description,

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Compare the requested name against Twitter's 25-character list name limit and shorten it
  2. Check for special characters that Twitter may escape or normalize, and avoid them
  3. Verify the expectedName passed to requireCreateListResult matches the name actually sent in the CreateList variables
  4. Re-run the command; if persistent, inspect the response payload for the actual name

Example fix

// before
const name = 'My very long list name exceeding limits';
// after
const name = args.name.slice(0, 25); // respect Twitter's max list name length
Defensive patterns

Strategy: validation

Validate before calling

const requested = name.trim();
if (requested.length > 25) throw new Error('Twitter list names max 25 characters');
if (requested !== expectedName?.trim()) throw new Error('expectedName does not match requested name');

Type guard

function nameMatches(list, expected) {
  return typeof list?.name === 'string' && list.name.trim() === String(expected).trim();
}

Try / catch

try {
  const row = buildListCreateRow({ result, name, description, mode });
} catch (e) {
  if (/CreateList returned name/.test(e.message)) console.error('Name mismatch:', e.message, '— check truncation/escaping');
  else throw e;
}

Prevention

When it happens

Trigger: 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).

Common situations: 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.

Understand the failure class

Background: Schema validation failed / invalid input schema: payload rejected because its shape doesn't match the expected schema — this error's family across 28 libraries.

Related errors


AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29). Data as JSON: /api/errors/284eef8b2b8adaeb. Report an issue: GitHub.