jackwener/OpenCLI · error · CommandExecutionError

archive wayback failed: HTTP ${resp.status}

Error message

archive wayback failed: HTTP ${resp.status}

What it means

Thrown by the `wayback` command in the archive CLI when the Wayback Machine save API responds with a non-2xx HTTP status. The library wraps this in a CommandExecutionError with the status code so the caller knows the archive request itself failed (as opposed to a network error, which is reported separately). It indicates the Wayback service rejected or failed to process the save request.

Source

Thrown at clis/archive/wayback.js:58

        const timestamp = args.timestamp ? normalizeTimestamp(args.timestamp) : '';

        const apiUrl = new URL('https://archive.org/wayback/available');
        apiUrl.searchParams.set('url', target);
        if (timestamp) apiUrl.searchParams.set('timestamp', timestamp);

        let resp;
        try {
            resp = await fetch(apiUrl, {
                headers: {
                    'Accept': 'application/json',
                    'User-Agent': 'opencli/1.0 (+https://github.com/jackwener/opencli)',
                },
            });
        } catch (error) {
            throw new CommandExecutionError(`archive wayback request failed: ${error?.message || error}`);
        }
        if (!resp.ok) {
            throw new CommandExecutionError(`archive wayback failed: HTTP ${resp.status}`);
        }
        let data;
        try {
            data = await resp.json();
        } catch (error) {
            throw new CommandExecutionError(`archive wayback returned malformed JSON: ${error?.message || error}`);
        }

        const snap = data?.archived_snapshots?.closest;
        if (!snap || !snap.available) {
            throw new EmptyResultError('archive wayback', `No Wayback snapshot for "${target}".`);
        }
        if (typeof snap.url !== 'string' || !snap.url || !/^\d{14}$/.test(String(snap.timestamp ?? ''))) {
            throw new CommandExecutionError('archive wayback returned malformed payload: closest snapshot is missing url/timestamp');
        }

        return [{
            original_url: String(data.url ?? target),

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Check resp.status in the message and retry after a delay if 429/503 (Wayback rate limits aggressively)
  2. Test the target URL in a browser at web.archive.org/save/<url> to confirm the service accepts it
  3. Retry later if the status is 5xx — the Wayback service may be temporarily down
  4. If 403 persists, the URL or client may be blocked; try from a different network or use the official Save Page Now API with credentials

Example fix

// before
await exec('opencli archive wayback https://example.com'); // throws on 429
// after
for (let attempt = 0; attempt < 3; attempt++) {
  try { return await exec('opencli archive wayback ' + url); }
  catch (e) {
    if (!/HTTP (429|503)/.test(e.message) || attempt === 2) throw e;
    await new Promise(r => setTimeout(r, 5000 * (attempt + 1)));
  }
}
Defensive patterns

Strategy: retry

Validate before calling

const url = 'https://example.com';
if (!/^https?:\/\//.test(url)) throw new Error('need an absolute http(s) URL before archiving');

Type guard

function isArchivableUrl(u) { return typeof u === 'string' && /^https?:\/\/\S+$/.test(u); }

Try / catch

try {
  await runWayback(url);
} catch (e) {
  const m = e.message.match(/HTTP (\d{3})/);
  if (m && ['429', '502', '503', '504'].includes(m[1])) {
    await sleep(5000); return runWayback(url); // retry once on rate-limit/server errors
  }
  throw e;
}

Prevention

When it happens

Trigger: Calling `opencli archive wayback <url>` when resp.ok is false: HTTP 403/429 rate limiting or bot blocking by web.archive.org, HTTP 5xx while the Wayback service is degraded, or 4xx for URLs the archive refuses.

Common situations: Bulk-archiving many URLs in a loop and tripping rate limits; archiving during Wayback outages; URL schemes the Wayback save endpoint rejects.

Related errors


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