jackwener/OpenCLI · error · CommandExecutionError

Failed to fetch YouTube feed

Error message

Failed to fetch YouTube feed

What it means

CommandExecutionError raised by `youtube feed` when the in-page script returns a non-array and no error string could be extracted from it. The fallback message 'Failed to fetch YouTube feed' is thrown, meaning the feed extraction failed without YouTube surfacing a specific reason.

Source

Thrown at clis/youtube/feed.js:114

            const newItems = contData.onResponseReceivedActions?.[0]?.appendContinuationItemsAction?.continuationItems || [];
            if (!newItems.length) break;
            for (const item of newItems) {
              if (videos.length >= limit) break;
              const v = extractFromItem(item);
              if (v?.video_id) {
                videos.push({ rank: videos.length + 1, ...v, url: 'https://www.youtube.com/watch?v=' + v.video_id });
              }
            }
            contItem = newItems[newItems.length - 1];
          }
        }

        return videos;
      })()
    `);
        if (!Array.isArray(data)) {
            const errMsg = data && typeof data === 'object' ? String(data.error || '') : '';
            throw new CommandExecutionError(errMsg || 'Failed to fetch YouTube feed');
        }
        if (data.length === 0) {
            throw new EmptyResultError('youtube feed');
        }
        return data;
    },
});

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Re-run the command — transient page-load issues often resolve on retry.
  2. Check login/cookie state; the personalized feed may require an active session.
  3. If it fails consistently, the feed DOM likely changed — update or patch the extractor script.
  4. Log the raw `data` value by wrapping the call to see what the page actually returned.

Example fix

// before
await yt.feed(); // opaque 'Failed to fetch YouTube feed'
// after
try {
  await yt.feed();
} catch (e) {
  if (e instanceof CommandExecutionError && e.message === 'Failed to fetch YouTube feed') {
    console.error('Feed scrape returned non-array data; check session/DOM');
  } else throw e;
}
Defensive patterns

Strategy: try-catch

Type guard

function isVideoArray(d) {
  return Array.isArray(d);
}

Try / catch

try {
  const feed = await yt.feed();
} catch (e) {
  if (e instanceof CommandExecutionError) {
    // non-array, non-error payload — likely DOM change or unrendered page
    await sleep(2000);
    return yt.feed(); // single retry
  }
  throw e;
}

Prevention

When it happens

Trigger: Running `youtube feed` when the embedded evaluate returns a non-array object lacking a usable `error` string — e.g. null/undefined result, an unexpected object shape after a YouTube DOM change, or the page failing to render the feed in time.

Common situations: Logged-out session where the home feed does not render; YouTube A/B test or redesign changing selectors; slow page load causing the script to resolve with a non-array placeholder; browser page crash mid-scrape.

Related errors


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