{"record":{"id":"88b43b37e090119f","repo":"jackwener/OpenCLI","slug":"rest-countries-label-cannot-be-empty","errorCode":null,"errorMessage":"rest-countries ${label} cannot be empty","messagePattern":"rest-countries (.+?) cannot be empty","errorType":"validation","errorClass":"ArgumentError","httpStatus":null,"severity":"error","filePath":"clis/rest-countries/utils.js","lineNumber":24,"sourceCode":"import { ArgumentError, CommandExecutionError, EmptyResultError } from '@jackwener/opencli/errors';\n\nexport const REST_COUNTRIES_BASE = 'https://restcountries.com/v3.1';\nconst UA = 'opencli-rest-countries-adapter/1.0 (+https://github.com/jackwener/opencli; mailto:opencli@example.com)';\n\n// REST Countries valid region values; subregions are validated server-side.\nexport const REST_COUNTRIES_REGIONS = new Set(['africa', 'americas', 'asia', 'europe', 'oceania', 'antarctic']);\n\n// Fields the adapter always requests; keep this list aligned with `columns` so\n// rows never have null-where-absent silent drops.\nexport const COUNTRY_FIELDS = [\n    'name', 'cca2', 'cca3', 'ccn3', 'capital', 'region', 'subregion',\n    'population', 'area', 'languages', 'currencies', 'flag', 'latlng', 'timezones',\n    'independent', 'unMember', 'landlocked',\n].join(',');\n\nexport function requireString(value, label) {\n    const s = String(value ?? '').trim();\n    if (!s) throw new ArgumentError(`rest-countries ${label} cannot be empty`);\n    return s;\n}\n\nexport function requireBoundedInt(value, defaultValue, maxValue, label = 'limit') {\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(`rest-countries ${label} must be a positive integer`);\n    }\n    if (n > maxValue) {\n        throw new ArgumentError(`rest-countries ${label} must be <= ${maxValue}`);\n    }\n    return n;\n}\n\nexport function requireRegion(value) {\n    const raw = String(value ?? '').trim().toLowerCase();\n    if (!raw) throw new ArgumentError('rest-countries region is required (e.g. \"europe\", \"asia\")');","sourceCodeStart":6,"sourceCodeEnd":42,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/rest-countries/utils.js#L6-L42","documentation":"requireString validates that a labeled string argument is non-empty after trimming; otherwise it throws ArgumentError with 'rest-countries ${label} cannot be empty'. It is a guard so commands fail fast with a clear message instead of building malformed URLs. `value ?? ''` means null/undefined also trigger it.","triggerScenarios":"Calling the rest-countries country command without a `name` argument, or with name = '' / whitespace / null, so `String(value ?? '').trim()` is empty at clis/rest-countries/utils.js:24.","commonSituations":"Missing CLI flag or config key; passing an empty environment variable; a script interpolating an unset variable into the name argument.","solutions":["Pass a non-empty `name` argument to the country command.","Check the calling script/config for unset or empty variables feeding the name.","Validate required inputs before invoking the command.","Catch ArgumentError and print usage help."],"exampleFix":"// before\nawait countryCommand({ name: process.env.COUNTRY ?? '' });\n// after\nif (!process.env.COUNTRY) throw new Error('COUNTRY env var is required');\nawait countryCommand({ name: process.env.COUNTRY });","handlingStrategy":"validation","validationCode":"if (typeof name !== 'string' || name.trim() === '') {\n  throw new TypeError('name is required and must be a non-empty string');\n}","typeGuard":"function isNonEmptyString(v) { return typeof v === 'string' && v.trim().length > 0; }","tryCatchPattern":"try {\n  await countryCommand({ name });\n} catch (err) {\n  if (err instanceof ArgumentError && /cannot be empty/.test(err.message)) {\n    printUsage('name is required');\n  } else {\n    throw err;\n  }\n}","preventionTips":["Validate all required CLI args before invoking commands.","Never pass process.env values directly without an emptiness check.","Default missing required inputs to prompts or hard failures, not ''.","Write integration tests for the missing-argument path."],"tags":["argument-error","validation","cli","rest-countries"],"backgroundTag":"missing-required-argument","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}