jackwener/OpenCLI · error · ArgumentError

Invalid listId: ${JSON.stringify(kwargs.listId)}. Expected n

Error message

Invalid listId: ${JSON.stringify(kwargs.listId)}. Expected numeric ID.

What it means

An ArgumentError from listAddUser in `clis/twitter/list-add-core.js` thrown when kwargs.listId is missing, empty, or not purely numeric after trimming. The CLI requires the raw numeric X list ID (e.g. 123456789), not a slug like 'my-list' or a full x.com/i/lists/... URL, and includes an example usage in the error.

Source

Thrown at clis/twitter/list-add-core.js:108

        );
    }
    const verifiedBy = `member_count ${memberCountBefore} → ${memberCountAfter}`;
    return {
        listId,
        username,
        userId: String(userId),
        status: noop ? 'noop' : 'success',
        message: noop
            ? `@${username} is already a member of list ${listId}`
            : `Added @${username} to list ${listId} (verified via ${verifiedBy})`,
    };
}

export async function listAddUser(page, kwargs) {
        const listId = String(kwargs.listId || '').trim();
        const username = String(kwargs.username || '').replace(/^@/, '').trim();
        if (!listId || !/^\d+$/.test(listId)) {
            throw new ArgumentError(`Invalid listId: ${JSON.stringify(kwargs.listId)}. Expected numeric ID.`, 'Example: opencli twitter list-add 123456789 alice');
        }
        if (!username) {
            throw new ArgumentError('twitter list-add username is required', 'Example: opencli twitter list-add 123456789 alice');
        }
        // Strategy.UI does not get a domain URL pre-nav from the framework.
        // This page context is load-bearing for pre-target GraphQL calls below.
        await page.goto('https://x.com');
        await page.wait(3);
        const cookies = await page.getCookies({ url: 'https://x.com' });
        const ct0 = cookies.find((c) => c.name === 'ct0')?.value || null;
        if (!ct0) throw new AuthRequiredError('x.com', 'Not logged into x.com (no ct0 cookie)');

        const userByScreenNameQueryId = await resolveTwitterQueryId(page, 'UserByScreenName', USER_BY_SCREEN_NAME_QUERY_ID);

        const headers = JSON.stringify({
            'Authorization': `Bearer ${decodeURIComponent(TWITTER_BEARER_TOKEN)}`,
            'X-Csrf-Token': ct0,
            'X-Twitter-Auth-Type': 'OAuth2Session',

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Extract the numeric ID from the list URL (the digits in x.com/i/lists/<id>) and pass only that.
  2. Strip any surrounding URL/slug before calling — String(listId).trim() must match /^\d+$/.
  3. Ensure the listId variable is actually populated before invoking listAddUser.
  4. Use the documented form: opencli twitter list-add 123456789 alice

Example fix

// before
await listAddUser(page, { listId: 'https://x.com/i/lists/123456789', username: 'alice' });
// after
const listId = url.match(/\/lists\/(\d+)/)?.[1];
await listAddUser(page, { listId, username: 'alice' });
Defensive patterns

Strategy: validation

Validate before calling

function toNumericListId(input) {
  const s = String(input ?? '').trim();
  const fromUrl = s.match(/\/lists\/(\d+)/)?.[1];
  const id = fromUrl ?? s;
  if (!/^\d+$/.test(id)) throw new Error(`listId must be numeric, got: ${input}`);
  return id;
}
const listId = toNumericListId(rawListId);

Type guard

function isValidListId(v) {
  return typeof v !== 'undefined' && v !== null && /^\d+$/.test(String(v).trim());
}

Try / catch

try {
  await listAddUser(page, { listId, username });
} catch (e) {
  if (e instanceof ArgumentError && /Invalid listId/.test(e.message)) {
    // message includes the expected format and an example invocation
    console.error('Pass the numeric list ID, e.g. opencli twitter list-add 123456789 alice');
  }
  throw e;
}

Prevention

When it happens

Trigger: listAddUser called with listId undefined/null, an empty string, a list slug ('my-cool-list'), a URL ('https://x.com/i/lists/123456789'), or a value with non-digit characters.

Common situations: Passing the list name from the X UI instead of its numeric ID; pasting the whole list URL; forgetting the listId argument so undefined is passed; scripting with a variable that was never set.

Related errors


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