jackwener/OpenCLI · error · CommandExecutionError

archive wayback returned malformed payload: closest snapshot

Error message

archive wayback returned malformed payload: closest snapshot is missing url/timestamp

What it means

A CommandExecutionError thrown when the Wayback snapshot object exists and is marked available but fails shape validation: url is not a non-empty string, or timestamp is not a 14-digit string (e.g. "20240101120000"). The library treats this as a malformed API payload rather than an empty result, because the data is present but unusable for building the output row.

Source

Thrown at clis/archive/wayback.js:72

        } 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),
            requested_timestamp: timestamp,
            snapshot_timestamp: String(snap.timestamp ?? ''),
            snapshot_url: String(snap.url),
            status: String(snap.status ?? ''),
        }];
    },
});

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Re-run the command — sparse payloads are often transient during save processing
  2. Log/print the full API response (curl the save endpoint) to inspect the actual snapshot shape
  3. Check whether the archive CLI or Wayback API has been updated (schema drift)
  4. Report/patch: loosen the validation or map the new field format in wayback.js

Example fix

// before
if (typeof snap.url !== 'string' || !snap.url || !/^\d{14}$/.test(String(snap.timestamp ?? ''))) {
  throw new CommandExecutionError('archive wayback returned malformed payload: ...');
}
// after
const ts = String(snap.timestamp ?? '');
if (!snap.url || !/\d{14}/.test(ts)) {
  // tolerate ISO timestamps by stripping non-digits before validating
  if (!/^\d{14}$/.test(ts.replace(/\D/g, '').slice(0, 14))) {
    throw new CommandExecutionError('archive wayback returned malformed payload: closest snapshot is missing url/timestamp');
  }
}
Defensive patterns

Strategy: type-guard

Validate before calling

null

Type guard

function isValidSnapshot(snap) {
  return !!snap && snap.available === true
    && typeof snap.url === 'string' && snap.url.length > 0
    && /^\d{14}$/.test(String(snap.timestamp ?? ''));
}

Try / catch

try {
  return await runWayback(url);
} catch (e) {
  if (e.message.includes('malformed payload')) {
    console.error('Wayback API schema deviation; inspect raw response and retry');
    await sleep(3000);
    return runWayback(url); // sparse payloads are often transient
  }
  throw e;
}

Prevention

When it happens

Trigger: `opencli archive wayback <url>` where the closest snapshot has snap.url missing/not a string, or snap.timestamp missing or not matching /^\d{14}$/ — i.e. the Wayback API response schema deviates from the expected format.

Common situations: Wayback API schema changes or A/B rollouts returning new field formats; partially completed save jobs with sparse snapshot objects; unexpected API responses during service incidents.

Understand the failure class

Background: Schema validation failed / invalid input schema: payload rejected because its shape doesn't match the expected schema — this error's family across 28 libraries.

Related errors


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