jackwener/OpenCLI · error · CommandExecutionError

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

Error message

Invalid listId: ${JSON.stringify(kwargs.listId)}. Expected a numeric ID (see `opencli twitter lists`).

What it means

The `twitter list-tweets` command requires listId to be a non-empty string of digits (X list IDs are large numeric identifiers). Empty, non-numeric, or float-form input is rejected immediately with a CommandExecutionError before any network work.

Source

Thrown at clis/twitter/list-tweets.js:132

cli({
    site: 'twitter',
    name: 'list-tweets',
    access: 'read',
    description: 'Fetch tweets from a Twitter/X list timeline',
    domain: 'x.com',
    strategy: Strategy.COOKIE,
    browser: true,
    args: [
        { name: 'listId', positional: true, type: 'string', required: true, help: 'Numeric ID of a Twitter/X list (e.g. from `opencli twitter lists`)' },
        { name: 'limit', type: 'int', default: 50 },
        { name: 'top-by-engagement', type: 'int', default: 0, help: 'When set to N>0, re-rank the list timeline by weighted engagement (likes×1 + retweets×3 + replies×2 + bookmarks×5 + log10(views+1)×0.5) and return the top N. Default 0 keeps the list\'s native (recency) ordering.' },
    ],
    columns: ['id', 'author', 'bio', 'text', 'likes', 'retweets', 'replies', 'created_at', 'url', 'has_media', 'media_urls', 'media_posters', 'card', 'quoted_tweet'],
    func: async (page, kwargs) => {
        const listId = String(kwargs.listId || '').trim();
        if (!listId || !/^\d+$/.test(listId)) {
            throw new CommandExecutionError(`Invalid listId: ${JSON.stringify(kwargs.listId)}. Expected a numeric ID (see \`opencli twitter lists\`).`);
        }
        const limit = kwargs.limit || 50;
        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)');
        // opencli >=1.7.x wraps primitive page.evaluate returns as { session, data: <value> }.
        // Without unwrap, the string queryId becomes "[object Object]" when interpolated into the URL,
        // causing HTTP 400 "queryId may have expired".
        const unwrap = (v) => (v && typeof v === 'object' && 'session' in v && 'data' in v ? v.data : v);
        const queryIdRaw = await page.evaluate(`async () => {
            try {
                const ghResp = await fetch('https://raw.githubusercontent.com/fa0311/twitter-openapi/refs/heads/main/src/config/placeholder.json');
                if (ghResp.ok) {
                    const data = await ghResp.json();
                    const entry = data['${OPERATION_NAME}'];
                    if (entry && entry.queryId) return entry.queryId;
                }

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Get the numeric ID with `opencli twitter lists` and pass it as-is, e.g. --listId 1234567890123456789
  2. If the id comes from JSON, keep it as a string — large ids lose precision as JS numbers
  3. Trim whitespace / strip URL prefixes: use only the digits from an x.com/i/lists/<id> URL
  4. Fix the calling script so the flag/field is actually populated (undefined → this error)

Example fix

// before
const listId = BigInt(rawId); // serializes oddly / may be NaN-ish
await run('twitter', 'list-tweets', { listId });
// after
const listId = String(rawId).trim();
if (!/^\d+$/.test(listId)) throw new Error(`listId must be numeric digits, got: ${rawId}`);
await run('twitter', 'list-tweets', { listId });
Defensive patterns

Strategy: validation

Validate before calling

function validListId(v){ const s = String(v ?? '').trim(); return /^\d+$/.test(s) ? s : null; }
const listId = validListId(kwargs.listId);
if (!listId) throw new Error(`listId must be numeric digits, got ${JSON.stringify(kwargs.listId)}`);

Type guard

const isNumericId = (v) => typeof v === 'string' && /^\d+$/.test(v.trim());

Try / catch

try {
  await run('twitter', 'list-tweets', { listId });
} catch (e) {
  if (String(e.message).startsWith('Invalid listId')) {
    const lists = await run('twitter', 'lists', {}); // help the user resolve the real id
    console.error('Pick a numeric id from:', lists.map(l => `${l.id} ${l.name}`));
  } else throw e;
}

Prevention

When it happens

Trigger: Calling the command with listId missing/empty ('' or undefined), with a non-numeric value ('my-list'), a float ('123.0' fails? no — '.' fails the ^\d+$ test), a number in scientific notation, or an object; String() is applied first, so only digit-only strings pass.

Common situations: Passing a list name instead of an ID; copying the list's URL slug/owner handle instead of the numeric id; JSON tooling serializing the big id as a float (1.9e18) or quoted-with-spaces value; forgetting the --listId flag so kwargs.listId is undefined.

Related errors


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