jackwener/OpenCLI · error · CommandExecutionError

Failed to fetch YouTube history

Error message

Failed to fetch YouTube history

What it means

CommandExecutionError thrown by the youtube history command when the in-page scrape finished but returned an unrecognized failure (any result.error other than 'timeout' or 'empty', or an error message string). It is the generic catch-all for a failed YouTube watch-history fetch. The library throws it because the scrape could not be classified as a timeout or an empty-result case.

Source

Thrown at clis/youtube/history.js:267

        return {
          error: 'page-cap',
          message: 'YouTube history pagination stopped before satisfying the requested limit',
        };
      })()
    `);

        if (Array.isArray(result)) return result;
        if (result?.error === 'auth') {
            throw new AuthRequiredError('www.youtube.com', result.message || 'Not logged in to YouTube');
        }
        if (result?.error === 'timeout') {
            throw new TimeoutError('YouTube history request', REQUEST_TIMEOUT_SECONDS);
        }
        if (result?.error === 'empty') {
            throw new EmptyResultError('youtube history', result.message || 'No watch history items found');
        }
        throw new CommandExecutionError(result?.message || 'Failed to fetch YouTube history');
    },
});

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Re-run the command once — transient page-load failures are common
  2. Verify you are logged into YouTube in the CLI's browser profile (history requires auth)
  3. Clear stale cookies/consent state for www.youtube.com in the profile and retry
  4. Update the CLI package so scrape selectors match the current YouTube DOM
  5. Check stderr/output for the underlying result.message for the real cause

Example fix

// before
opencli youtube history
// after
opencli youtube history --debug   # see underlying result.message; re-auth profile if needed
Defensive patterns

Strategy: try-catch

Validate before calling

null

Type guard

function isCommandFailure(r) { return r && typeof r === 'object' && 'error' in r; }

Try / catch

try {
  const rows = await run('youtube history');
} catch (e) {
  if (/history/i.test(e.message)) {
    console.error('History fetch failed:', e.message, '— check YouTube login and retry');
  } else throw e;
}

Prevention

When it happens

Trigger: The page.evaluate scrape of the watch-history page returns {error: ...} with an unexpected code (e.g. 'http', 'nav', 'config'), or result is missing the expected fields; typically YouTube DOM changes, redirects to a consent/login page, or a non-200 response during scraping.

Common situations: YouTube layout updates breaking the scrape selectors, hitting a consent screen, account without watch history yet in an unexpected state, transient network failure mid-page-load, or a headless browser page rendered as a bot-check page.

Related errors


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