{"record":{"id":"95a3a8a5dcbb055f","repo":"jackwener/OpenCLI","slug":"mdn-label-cannot-be-empty","errorCode":null,"errorMessage":"mdn ${label} cannot be empty","messagePattern":"mdn (.+?) cannot be empty","errorType":"validation","errorClass":"ArgumentError","httpStatus":null,"severity":"error","filePath":"clis/mdn/search.js","lineNumber":15,"sourceCode":"// mdn search — search MDN Web Docs.\n//\n// Hits `https://developer.mozilla.org/api/v1/search?q=…&locale=…`. Returns a\n// row per matched doc with title, slug-derived id, summary preview, and the\n// canonical MDN URL.\nimport { cli, Strategy } from '@jackwener/opencli/registry';\nimport { ArgumentError, CommandExecutionError, EmptyResultError } from '@jackwener/opencli/errors';\n\nconst MDN_BASE = 'https://developer.mozilla.org';\nconst UA = 'opencli-mdn-adapter (+https://github.com/jackwener/opencli)';\nconst ALLOWED_LOCALES = new Set(['en-US', 'de', 'es', 'fr', 'ja', 'ko', 'pt-BR', 'ru', 'zh-CN', 'zh-TW']);\n\nfunction requireString(value, label) {\n    const s = String(value ?? '').trim();\n    if (!s) throw new ArgumentError(`mdn ${label} cannot be empty`);\n    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)) {","sourceCodeStart":1,"sourceCodeEnd":33,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/mdn/search.js#L1-L33","documentation":"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.","triggerScenarios":"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).","commonSituations":"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.","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."],"exampleFix":"// before\nconst query = process.env.Q; // may be undefined\nawait mdnSearch(query);\n// after\nconst query = process.env.Q?.trim();\nif (!query) { console.error('usage: mdn search <query>'); process.exit(2); }\nawait mdnSearch(query);","handlingStrategy":"validation","validationCode":"const q = (value ?? '').trim();\nif (!q) throw new TypeError('mdn query cannot be empty');","typeGuard":"function isNonEmptyString(v) { return typeof v === 'string' && v.trim().length > 0; }","tryCatchPattern":"try { await mdnSearch({ query }); } catch (e) { if (String(e.message).startsWith('mdn query cannot be empty')) { printUsage(); } else throw e; }","preventionTips":["Trim and check user input before calling","Fail fast with usage messages in CLI wrappers","Quote shell arguments to avoid silent empty expansion"],"tags":["validation","argument-error","cli"],"backgroundTag":"empty-required-argument","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}