jackwener/OpenCLI · error · CommandExecutionError
String(data.error)
Error message
String(data.error)
What it means
CommandExecutionError raised by `youtube channel` when the in-page evaluate script returns an object with an `error` property. The library forwards YouTube's own error string (String(data.error)) so the developer sees the underlying page-side failure. It means the fetch script ran but reported a failure instead of channel data.
Source
Thrown at clis/youtube/channel.js:205
}
}
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
- Read the forwarded message — it is YouTube's own error string; fix the underlying cause it names.
- Verify the channel handle/URL passed to the command exists and is current.
- Re-run after checking login/cookie state, since private/restricted data can surface as a page error.
- Retry later or update the library if YouTube changed its page structure (data.error persists for all channels).
Example fix
// before
const { data } = await run(); // throws with raw YouTube error string
// after
try {
const { data } = await run();
} catch (e) {
if (e instanceof CommandExecutionError) {
console.error('YouTube channel fetch failed:', e.message); // inspect forwarded page error
} else throw e;
} Defensive patterns
Strategy: try-catch
Validate before calling
const handle = 'yours';
if (!handle || typeof handle !== 'string') throw new Error('channel handle required'); Type guard
function hasError(d) {
return typeof d === 'object' && d !== null && 'error' in d && Boolean(d.error);
} Try / catch
try {
const channel = await yt.channel(handle);
} catch (e) {
if (e instanceof CommandExecutionError) {
console.error(`channel fetch failed: ${e.message}`); // message is YouTube's own error
} else throw e;
} Prevention
- Validate the channel handle/URL before invoking.
- Check YouTube login/cookie state for restricted channels.
- Retry on transient failures; treat persistent errors for all channels as a DOM change needing a library update.
- Log the forwarded message — it names the page-side cause.
When it happens
Trigger: Running the `youtube channel` command when the embedded page.evaluate script returns {error: ...} — e.g. YouTube returned an error response, the channel handle/ID does not resolve, or the page DOM/API shape changed and the script caught an exception and reported it via data.error.
Common situations: Scraping a non-existent or removed channel handle; running without a page prepared for YouTube (region/consent wall); YouTube internal API changes after a site update; transient network failures inside the browser page.
Related errors
- errMsg
- Failed to fetch YouTube feed
- Failed to fetch YouTube history
- Failed to fetch playlist data
- String(data.error)
AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29).
Data as JSON: /api/errors/c2e55f04dea102f2.
Report an issue: GitHub.