jackwener/OpenCLI · error · CommandExecutionError

String(payload.error)

Error message

String(payload.error)

What it means

CommandExecutionError thrown when the extracted video payload itself carries an error field. The page-side extraction script detected a failure (e.g. the video page reported an error or a fetch failed) and returned it as { error: ... }; the library converts that string into a thrown CommandExecutionError.

Source

Thrown at clis/youtube/video.js:21

 */
import { cli, Strategy } from '@jackwener/opencli/registry';
import { extractJsonAssignmentFromHtml, parseVideoId, prepareYoutubeApiPage } from './utils.js';
import { CommandExecutionError } from '@jackwener/opencli/errors';

function unwrapBrowserResult(value) {
    if (value && typeof value === 'object' && 'session' in value && 'data' in value) {
        return value.data;
    }
    return value;
}

function requireVideoPayload(value) {
    const payload = unwrapBrowserResult(value);
    if (!payload || typeof payload !== 'object' || Array.isArray(payload)) {
        throw new CommandExecutionError('Failed to extract video metadata from page');
    }
    if (payload.error) {
        throw new CommandExecutionError(String(payload.error));
    }
    if (typeof payload.playabilityStatus !== 'string') {
        throw new CommandExecutionError('YouTube video metadata is missing playabilityStatus');
    }
    if (typeof payload.playabilityReason !== 'string') {
        throw new CommandExecutionError('YouTube video metadata is missing playabilityReason');
    }
    if (typeof payload.membersOnly !== 'boolean') {
        throw new CommandExecutionError('YouTube video metadata is missing membersOnly');
    }
    return payload;
}

cli({
    site: 'youtube',
    name: 'video',
    access: 'read',
    description: 'Get YouTube video metadata (title, views, description, etc.)',

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Use the thrown message (String(payload.error)) to identify the concrete page-side failure (e.g. HTTP status).
  2. Verify the video ID/URL is valid and publicly accessible in a normal browser.
  3. Handle restricted videos (private, deleted, region-locked) explicitly before retrying.
  4. Retry with backoff if the error suggests a transient HTTP/network failure; update the library if the page structure changed.

Example fix

// before
const info = await video(url); // throws CommandExecutionError
// after
try {
  const info = await video(url);
} catch (e) {
  if (e.name === 'CommandExecutionError') console.error('video fetch error:', e.message);
  throw e;
}
Defensive patterns

Strategy: try-catch

Try / catch

try {
  const info = await video(url);
} catch (e) {
  if (e.name === 'CommandExecutionError') {
    const detail = e.message;
    if (/HTTP 4\d\d/.test(detail)) {
      return handleUnavailableVideo(url, detail);
    }
    return retryWithBackoff(() => video(url));
  }
  throw e;
}

Prevention

When it happens

Trigger: payload.error is truthy — e.g. the in-page script captured 'HTTP 404' for a missing video, a playability failure it chose to surface as an error, or a page-side exception message.

Common situations: Deleted/private/geoblocked videos; network or HTTP failures while the page script fetched metadata; YouTube page changes causing the in-page script to fail; rate limiting or bot challenges.

Related errors


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