{"record":{"id":"388b31aa4657ba7e","repo":"jackwener/OpenCLI","slug":"rest-countries-region","errorCode":null,"errorMessage":"rest-countries region","messagePattern":"rest-countries region","errorType":"exception","errorClass":"EmptyResultError","httpStatus":null,"severity":"warning","filePath":"clis/rest-countries/region.js","lineNumber":59,"sourceCode":"        'languages',\n        'currencies',\n        'latitude',\n        'longitude',\n        'timezones',\n        'independent',\n        'unMember',\n        'landlocked',\n        'flag',\n        'url',\n    ],\n    func: async (args) => {\n        const region = requireRegion(args.region);\n        const limit = requireBoundedInt(args.limit, 250, 250);\n        const url = `${REST_COUNTRIES_BASE}/region/${encodeURIComponent(region)}?fields=${COUNTRY_FIELDS}`;\n        const body = await restCountriesFetch(url, 'rest-countries region');\n        const list = Array.isArray(body) ? body : [];\n        if (!list.length) {\n            throw new EmptyResultError('rest-countries region', `No countries returned for region \"${region}\".`);\n        }\n        const sorted = [...list].sort((a, b) => (b?.population ?? 0) - (a?.population ?? 0));\n        return sorted.slice(0, limit).map((c, i) => ({ rank: i + 1, ...projectCountry(c) }));\n    },\n});\n","sourceCodeStart":41,"sourceCodeEnd":65,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/rest-countries/region.js#L41-L65","documentation":"The rest-countries region command throws EmptyResultError when the /v3.1/region/{region} endpoint returns an empty list for a recognized region. This means the request was valid but the API returned no countries for that region string. The library raises it explicitly rather than returning an empty array.","triggerScenarios":"Calling the rest-countries region command where `requireRegion` accepted the value but `restCountriesFetch` returned an empty body, hitting `!list.length` at clis/rest-countries/region.js:59 (e.g. transient upstream data issues or an unusual region slug).","commonSituations":"Upstream API temporarily returning empty payloads; region value that passes local validation but the API maps to nothing; network proxies stripping response bodies.","solutions":["Retry the request; empty responses for a valid region are usually transient.","Verify the region value against the allowed set (africa, americas, asia, europe, oceania).","Check the raw endpoint in a browser/curl to confirm the API returns data.","Catch EmptyResultError and surface a friendly 'no data right now' message."],"exampleFix":"// before\nawait regionCommand({ region: 'Antarctica' });\n// after\nawait regionCommand({ region: 'europe' });","handlingStrategy":"retry","validationCode":"const REGIONS = new Set(['africa','americas','asia','europe','oceania']);\nif (!REGIONS.has(String(args.region ?? '').trim().toLowerCase())) {\n  throw new Error('invalid or unknown region');\n}","typeGuard":"function isKnownRegion(v) {\n  return ['africa','americas','asia','europe','oceania'].includes(String(v ?? '').trim().toLowerCase());\n}","tryCatchPattern":"try {\n  const countries = await regionCommand({ region });\n} catch (err) {\n  if (err instanceof EmptyResultError) {\n    // empty payload for a valid region: retry once, then surface 'no data'\n  } else {\n    throw err;\n  }\n}","preventionTips":["Retry once on empty responses for valid regions before surfacing failure.","Only use the API's five canonical region values.","Verify upstream health (curl the region endpoint) if empties persist.","Cache region results to reduce dependence on transient upstream state."],"tags":["empty-result","rest-countries","api"],"backgroundTag":"empty-result-set","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}