jackwener/OpenCLI · error · ArgumentError
mdn ${label} cannot be empty
Error message
mdn ${label} cannot be empty What it means
clis/mdn/search.js validates user input with requireString, which coerces its argument to a string and trims it. If the result is empty (missing, null, undefined, or whitespace-only), it throws an ArgumentError with the label embedded. This guards the MDN search API against empty query parameters.
Source
Thrown at clis/mdn/search.js:15
// mdn search — search MDN Web Docs.
//
// Hits `https://developer.mozilla.org/api/v1/search?q=…&locale=…`. Returns a
// row per matched doc with title, slug-derived id, summary preview, and the
// canonical MDN URL.
import { cli, Strategy } from '@jackwener/opencli/registry';
import { ArgumentError, CommandExecutionError, EmptyResultError } from '@jackwener/opencli/errors';
const MDN_BASE = 'https://developer.mozilla.org';
const UA = 'opencli-mdn-adapter (+https://github.com/jackwener/opencli)';
const ALLOWED_LOCALES = new Set(['en-US', 'de', 'es', 'fr', 'ja', 'ko', 'pt-BR', 'ru', 'zh-CN', 'zh-TW']);
function requireString(value, label) {
const s = String(value ?? '').trim();
if (!s) throw new ArgumentError(`mdn ${label} cannot be empty`);
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)) {View on GitHub (pinned to 49907e53dc)
Solutions
- Provide a non-empty query string to the mdn search command or function.
- Check the variable or argument being passed actually holds a value before calling (echo/print it).
- Trim and check the value in your own script before invoking; exit early with a clear message.
- Quote shell arguments so stray flags or pipes do not swallow the query.
Example fix
// before
const query = process.env.Q; // may be undefined
await mdnSearch(query);
// after
const query = process.env.Q?.trim();
if (!query) { console.error('usage: mdn search <query>'); process.exit(2); }
await mdnSearch(query); Defensive patterns
Strategy: validation
Validate before calling
const q = (value ?? '').trim();
if (!q) throw new TypeError('mdn query cannot be empty'); Type guard
function isNonEmptyString(v) { return typeof v === 'string' && v.trim().length > 0; } Try / catch
try { await mdnSearch({ query }); } catch (e) { if (String(e.message).startsWith('mdn query cannot be empty')) { printUsage(); } else throw e; } Prevention
- Trim and check user input before calling
- Fail fast with usage messages in CLI wrappers
- Quote shell arguments to avoid silent empty expansion
When it happens
Trigger: Calling the mdn search command or its exported search function with an empty, null, undefined, or whitespace-only value for the parameter bound to requireString's label (e.g. the search query).
Common situations: Passing shell variables that are unset (mdn search "$QUERY" with QUERY empty); chaining commands where a previous step produced no output; programmatically passing null/undefined query values.
Related errors
- archive search sort must be one of ${SORT_OPTIONS.join(', ')
- archive search mediatype must be one of ${MEDIATYPES.join(',
- archive search limit must be a positive integer
- archive search limit must be <= 100
- archive search query must not be empty
AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29).
Data as JSON: /api/errors/95a3a8a5dcbb055f.
Report an issue: GitHub.