{"record":{"id":"1562361ac2f6ef58","repo":"jackwener/OpenCLI","slug":"mdn-locale-value-is-not-supported","errorCode":null,"errorMessage":"mdn locale \"${value}\" is not supported","messagePattern":"mdn locale \"(.+?)\" is not supported","errorType":"validation","errorClass":"ArgumentError","httpStatus":null,"severity":"error","filePath":"clis/mdn/search.js","lineNumber":34,"sourceCode":"    return s;\n}\n\nfunction requireBoundedInt(value, defaultValue, maxValue) {\n    const raw = value ?? defaultValue;\n    const n = typeof raw === 'number' ? raw : Number(raw);\n    if (!Number.isInteger(n) || n <= 0) {\n        throw new ArgumentError('mdn limit must be a positive integer');\n    }\n    if (n > maxValue) {\n        throw new ArgumentError(`mdn limit must be <= ${maxValue}`);\n    }\n    return n;\n}\n\nfunction requireLocale(value) {\n    const s = String(value ?? 'en-US').trim();\n    if (!ALLOWED_LOCALES.has(s)) {\n        throw new ArgumentError(\n            `mdn locale \"${value}\" is not supported`,\n            `Allowed locales: ${[...ALLOWED_LOCALES].join(' / ')}`,\n        );\n    }\n    return s;\n}\n\ncli({\n    site: 'mdn',\n    name: 'search',\n    access: 'read',\n    description: 'Search MDN Web Docs by keyword',\n    domain: 'developer.mozilla.org',\n    strategy: Strategy.PUBLIC,\n    browser: false,\n    args: [\n        { name: 'query', positional: true, required: true, help: 'Search keyword (e.g. \"fetch\", \"flexbox\", \"Array.prototype.map\")' },\n        { name: 'limit', type: 'int', default: 10, help: 'Max results (1-50)' },","sourceCodeStart":16,"sourceCodeEnd":52,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/mdn/search.js#L16-L52","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Use one of the allowed locales exactly: en-US, de, es, fr, ja, ko, pt-BR, ru, zh-CN, zh-TW.","Map your locale to a supported one (e.g. 'en' -> 'en-US', 'zh' -> 'zh-CN').","Normalize case before passing: locale.trim() with correct casing ('en-US', 'pt-BR').","Omit the locale option to use the default en-US."],"exampleFix":"// before\nawait mdnSearch({ query: 'promise', locale: 'en' });\n// after\nconst LOCALES = { en: 'en-US', zh: 'zh-CN' };\nawait mdnSearch({ query: 'promise', locale: LOCALES['en'] ?? 'en-US' });","handlingStrategy":"validation","validationCode":"const ALLOWED = ['en-US','de','es','fr','ja','ko','pt-BR','ru','zh-CN','zh-TW'];\nif (!ALLOWED.includes(locale)) throw new RangeError(`unsupported locale: ${locale}`);","typeGuard":"function isSupportedLocale(v) { return typeof v === 'string' && ['en-US','de','es','fr','ja','ko','pt-BR','ru','zh-CN','zh-TW'].includes(v); }","tryCatchPattern":"try { await mdnSearch({ query, locale }); } catch (e) { if (String(e.message).includes('is not supported')) { return mdnSearch({ query, locale: 'en-US' }); } throw e; }","preventionTips":["Keep a constants list of supported locales and only pass values from it","Map bare language codes ('en') to full codes ('en-US')","Default to en-US when locale is unknown"],"tags":["validation","argument-error","i18n"],"backgroundTag":"unsupported-locale","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}