jackwener/OpenCLI · error · CommandExecutionError

Failed to fetch channel data

Error message

Failed to fetch channel data

What it means

After evaluating the channel-data extraction script in the YouTube page, the command checks that a non-null object came back; otherwise it throws 'Failed to fetch channel data'. It guards against the probe returning nothing usable (null/undefined/primitive).

Source

Thrown at clis/youtube/channel.js:203

              }
            }
          }
        }

        return {
          name: metadata.title || '',
          channelId: metadata.externalId || browseId,
          handle: metadata.vanityChannelUrl?.split('/').pop() || '',
          description: (metadata.description || '').substring(0, 500),
          subscribers: subscriberCount,
          url: metadata.channelUrl || 'https://www.youtube.com/channel/' + browseId,
          keywords: metadata.keywords || '',
          recentVideos,
        };
      })()
    `);
        if (!data || typeof data !== 'object')
            throw new CommandExecutionError('Failed to fetch channel data');
        if (data.error)
            throw new CommandExecutionError(String(data.error));
        const result = data;
        const videos = result.recentVideos;
        delete result.recentVideos;
        // Channel info as field/value pairs + recent videos as table
        const rows = Object.entries(result).map(([field, value]) => ({
            field,
            value: String(value),
        }));
        if (videos && videos.length > 0) {
            rows.push({ field: '---', value: '--- Recent Videos ---' });
            for (const v of videos) {
                rows.push({ field: v.title, value: `${v.duration} | ${v.views} | ${v.url}` });
            }
        }
        return rows;
    },

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Verify the URL/channel argument resolves to an existing channel page in a browser
  2. Ensure you are logged in (run auth) since some channels require a session
  3. Update the extraction script for current YouTube channel-page markup
  4. Retry — transient interstitials can be bypassed on a second load

Example fix

// before
await cli youtube channel 'https://www.youtube.com/@not-a-channel'
// after
await cli youtube channel 'https://www.youtube.com/@existinghandle'
Defensive patterns

Strategy: validation

Validate before calling

// confirm the target is a live channel page before scraping
const res = await fetch(channelUrl, { method: 'HEAD' });
if (!res.ok || res.url.includes('oops')) throw new Error('Channel page unavailable');

Type guard

function isChannelData(d) {
  return d !== null && typeof d === 'object' && !('error' in d);
}

Try / catch

try {
  await cli.youtube.channel(url);
} catch (e) {
  if (/Failed to fetch channel data/.test(e.message)) {
    console.error('No channel data returned; verify the channel URL and login state');
  } else throw e;
}

Prevention

When it happens

Trigger: The in-page script returned null because the current page is not a channel page, the channel doesn't exist/was terminated, or YouTube served a consent/login interstitial instead of channel data.

Common situations: Passing a video URL or handle that doesn't resolve to a channel; deleted/terminated channels; YouTube A/B layouts where the extraction script finds no data; age/region restrictions.

Related errors


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