jackwener/OpenCLI · error · ArgumentError

mdn locale "${value}" is not supported

Error message

mdn locale "${value}" is not supported

What it means

requireLocale checks the locale against ALLOWED_LOCALES (en-US, de, es, fr, ja, ko, pt-BR, ru, zh-CN, zh-TW). Any other value throws this ArgumentError, with a hint listing the allowed locales. This keeps queries within MDN's supported locale set.

Source

Thrown at clis/mdn/search.js:34

    return s;
}

function requireBoundedInt(value, defaultValue, maxValue) {
    const raw = value ?? defaultValue;
    const n = typeof raw === 'number' ? raw : Number(raw);
    if (!Number.isInteger(n) || n <= 0) {
        throw new ArgumentError('mdn limit must be a positive integer');
    }
    if (n > maxValue) {
        throw new ArgumentError(`mdn limit must be <= ${maxValue}`);
    }
    return n;
}

function requireLocale(value) {
    const s = String(value ?? 'en-US').trim();
    if (!ALLOWED_LOCALES.has(s)) {
        throw new ArgumentError(
            `mdn locale "${value}" is not supported`,
            `Allowed locales: ${[...ALLOWED_LOCALES].join(' / ')}`,
        );
    }
    return s;
}

cli({
    site: 'mdn',
    name: 'search',
    access: 'read',
    description: 'Search MDN Web Docs by keyword',
    domain: 'developer.mozilla.org',
    strategy: Strategy.PUBLIC,
    browser: false,
    args: [
        { name: 'query', positional: true, required: true, help: 'Search keyword (e.g. "fetch", "flexbox", "Array.prototype.map")' },
        { name: 'limit', type: 'int', default: 10, help: 'Max results (1-50)' },

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Use one of the allowed locales exactly: en-US, de, es, fr, ja, ko, pt-BR, ru, zh-CN, zh-TW.
  2. Map your locale to a supported one (e.g. 'en' -> 'en-US', 'zh' -> 'zh-CN').
  3. Normalize case before passing: locale.trim() with correct casing ('en-US', 'pt-BR').
  4. Omit the locale option to use the default en-US.

Example fix

// before
await mdnSearch({ query: 'promise', locale: 'en' });
// after
const LOCALES = { en: 'en-US', zh: 'zh-CN' };
await mdnSearch({ query: 'promise', locale: LOCALES['en'] ?? 'en-US' });
Defensive patterns

Strategy: validation

Validate before calling

const ALLOWED = ['en-US','de','es','fr','ja','ko','pt-BR','ru','zh-CN','zh-TW'];
if (!ALLOWED.includes(locale)) throw new RangeError(`unsupported locale: ${locale}`);

Type guard

function isSupportedLocale(v) { return typeof v === 'string' && ['en-US','de','es','fr','ja','ko','pt-BR','ru','zh-CN','zh-TW'].includes(v); }

Try / catch

try { await mdnSearch({ query, locale }); } catch (e) { if (String(e.message).includes('is not supported')) { return mdnSearch({ query, locale: 'en-US' }); } throw e; }

Prevention

When it happens

Trigger: Passing a locale like 'en', 'EN-US', 'zh', 'fr-FR', or a misspelled code to the mdn search locale option. Note the check is exact (case-sensitive) on the trimmed string.

Common situations: Using bare language codes ('en' instead of 'en-US'); wrong casing; regional variants MDN does not serve ('zh-HK', 'pt-PT'); defaults from other tooling.

Related errors


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