jackwener/OpenCLI · error · ArgumentError

archive snapshots ${key} must be a digit-only timestamp (YYY

Error message

archive snapshots ${key} must be a digit-only timestamp (YYYY[MM[DD[hh[mm[ss]]]]])

What it means

ArgumentError thrown when the optional `from` or `to` arguments are provided but are not digit-only strings of length 4–14, the Wayback timestamp format YYYY[MM[DD[hh[mm[ss]]]]]. The regex ^\d{4,14}$ enforces both character set and length; separators like dashes or colons are rejected.

Source

Thrown at clis/archive/snapshots.js:55

    func: async (args) => {
        const target = String(args.url ?? '').trim();
        if (!target) {
            throw new ArgumentError(
                'archive snapshots url cannot be empty',
                'Example: opencli archive snapshots wikipedia.org',
            );
        }
        const limit = Number(args.limit ?? 20);
        if (!Number.isInteger(limit) || limit <= 0) {
            throw new ArgumentError('archive snapshots limit must be a positive integer');
        }
        if (limit > 1000) {
            throw new ArgumentError('archive snapshots limit must be <= 1000');
        }
        for (const key of ['from', 'to']) {
            const v = args[key];
            if (v != null && !/^\d{4,14}$/.test(String(v))) {
                throw new ArgumentError(`archive snapshots ${key} must be a digit-only timestamp (YYYY[MM[DD[hh[mm[ss]]]]])`);
            }
        }

        // Wayback CDX is served on HTTP only; the HTTPS endpoint returns 503.
        const apiUrl = new URL('http://web.archive.org/cdx/search/cdx');
        apiUrl.searchParams.set('url', target);
        apiUrl.searchParams.set('output', 'json');
        apiUrl.searchParams.set('limit', String(limit));
        if (args.from) apiUrl.searchParams.set('from', String(args.from));
        if (args.to) apiUrl.searchParams.set('to', String(args.to));

        let resp;
        try {
            resp = await fetch(apiUrl, {
                headers: {
                    'Accept': 'application/json',
                    'User-Agent': 'opencli/1.0 (+https://github.com/jackwener/opencli)',
                },

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Convert to Wayback compact format: '2023-01-01' becomes 20230101.
  2. Use plain digits only, 4–14 chars: 2023, 202301, 20230101, up to 20230101120000.
  3. Generate the format in scripts: date -u +%Y%m%d (GNU date) for a today stamp.
  4. Omit from/to if a full-range query is acceptable.

Example fix

// before
opencli archive snapshots example.org --from 2023-01-01 --to 2023-12-31
// after
opencli archive snapshots example.org --from 20230101 --to 20231231
Defensive patterns

Strategy: validation

Validate before calling

// node
const WAYBACK_TS = /^\d{4,14}$/;
function toWaybackTs(iso) {
  return iso.replaceAll(/[-:T]/g, '').slice(0, 14);
}
if (from && !WAYBACK_TS.test(from)) from = toWaybackTs(from);

Type guard

function isWaybackTimestamp(v) {
  return typeof v === 'string' && /^\d{4,14}$/.test(v);
}

Try / catch

try {
  await run(['archive', 'snapshots', url, '--from', from, '--to', to]);
} catch (e) {
  if (/must be a digit-only timestamp/.test(e.message)) {
    const key = /snapshots (\w+)/.exec(e.message)?.[1];
    console.error(`reformat ${key} as digits only, e.g. 20230101`);
  } else throw e;
}

Prevention

When it happens

Trigger: Passing --from or --to values like '2023-01-01', '2023/01/01', '2023-01-01T00:00:00', an ISO 8601 string, a 3-digit year, or a >14-digit value.

Common situations: Copy-pasting ISO dates from logs; using human-readable date formats; shell variables carrying formatted dates from `date` command output.

Related errors


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