jackwener/OpenCLI · error · ArgumentError

--time must be one of d, w, m, or y

Error message

--time must be one of d, w, m, or y

What it means

The DuckDuckGo search command's optional --time filter maps to DuckDuckGo's df (date filter) parameter, which only accepts d (day), w (week), m (month), or y (year). Any other value fails a regex check and an ArgumentError is thrown before navigation.

Source

Thrown at clis/duckduckgo/search.js:96

  strategy: Strategy.PUBLIC,
  browser: true,
  args: [
    { name: 'keyword', positional: true, required: true, help: 'Search query' },
    { name: 'limit', type: 'int', default: 10, help: 'Number of results per page (1-10). For multi-page, use --offset' },
    { name: 'offset', type: 'int', default: 0, help: 'Result offset for pagination (0, 10, 20...). Uses XHR POST internally' },
    { name: 'region', help: 'Region code (e.g. jp-jp, us-en, cn-zh). Default: all regions' },
    { name: 'time', help: 'Time range: d (day), w (week), m (month), y (year)' },
  ],
  columns: ['rank', 'title', 'url', 'snippet', 'displayUrl', 'icon', 'resultType'],
  func: async (page, kwargs) => {
    const limit = requireBoundedInteger(kwargs.limit, 10, 1, 10, '--limit');
    const keyword = requireSearchQuery(kwargs.keyword);
    const offset = requireNonNegativeInteger(kwargs.offset, 0, '--offset');
    if (offset % 10 !== 0) {
      throw new ArgumentError('--offset must be a multiple of 10 for DuckDuckGo HTML pagination');
    }
    if (kwargs.time && !/^(d|w|m|y)$/.test(String(kwargs.time))) {
      throw new ArgumentError('--time must be one of d, w, m, or y');
    }
    let url = `https://html.duckduckgo.com/html/?q=${encodeURIComponent(keyword)}`;
    if (kwargs.region) url += `&kl=${encodeURIComponent(String(kwargs.region))}`;
    if (kwargs.time) url += `&df=${encodeURIComponent(String(kwargs.time))}`;
    await runBrowserStep('duckduckgo search navigation', () => page.goto(url));
    try {
      await page.wait({ selector: '.result', timeout: 8 });
    } catch {
      await page.wait(3).catch(function() {});
    }
    var raw;
    if (offset === 0) {
      raw = await runBrowserStep('duckduckgo search extraction', () => page.evaluate(buildExtractorJs(limit)));
    } else {
      raw = await runBrowserStep('duckduckgo search pagination extraction', () => page.evaluate(buildPaginateJs(limit, keyword, offset, kwargs.region)));
    }
    const rows = requireRows(raw, 'duckduckgo search');
    if (rows.length === 0) {

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Use exactly d, w, m, or y for --time
  2. Map verbose inputs ('day' -> 'd', 'month' -> 'm') before invoking
  3. Add a whitelist check on user input before passing it to the command
  4. Catch ArgumentError to give the user the accepted values

Example fix

// before
await ddgSearch({ keyword: 'cats', time: 'past week' });
// after
await ddgSearch({ keyword: 'cats', time: 'w' });
Defensive patterns

Strategy: validation

Validate before calling

const TIME_VALUES = ['d', 'w', 'm', 'y'];
if (time && !TIME_VALUES.includes(String(time))) {
  throw new Error('--time must be one of d, w, m, y');
}

Type guard

function isValidTime(t) {
  return t == null || ['d', 'w', 'm', 'y'].includes(String(t));
}

Prevention

When it happens

Trigger: Passing --time values like 'day', '24h', 'month', '1w', or a full date string instead of the single letters d, w, m, or y.

Common situations: Copying time-filter syntax from Google/Bing APIs into DuckDuckGo; writing 'week' instead of 'w'; scripts building the flag from user input without normalizing it.

Understand the failure class

Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.

Related errors


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