{"record":{"id":"e09bb770701ef1e0","repo":"jackwener/OpenCLI","slug":"rest-countries-country","errorCode":null,"errorMessage":"rest-countries country","messagePattern":"rest-countries country","errorType":"exception","errorClass":"EmptyResultError","httpStatus":null,"severity":"warning","filePath":"clis/rest-countries/country.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 name = requireString(args.name, 'name');\n        const limit = requireBoundedInt(args.limit, 25, 250);\n        const url = `${REST_COUNTRIES_BASE}/name/${encodeURIComponent(name)}?fields=${COUNTRY_FIELDS}`;\n        const body = await restCountriesFetch(url, 'rest-countries country');\n        const list = Array.isArray(body) ? body : [];\n        if (!list.length) {\n            throw new EmptyResultError('rest-countries country', `No countries matched \"${name}\".`);\n        }\n        // Sort by population descending so the most \"expected\" hit is first.\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":66,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/rest-countries/country.js#L41-L66","documentation":"The rest-countries country command throws EmptyResultError when the /v3.1/name/{name} endpoint returns an empty array, meaning no country matched the given name. The library converts that into an explicit, labeled error so callers see 'no countries matched' instead of silently getting []. It normalizes a valid HTTP 200 empty response into a searchable error.","triggerScenarios":"Calling the rest-countries country command with `args.name` whose encoded value yields `list.length === 0` at clis/rest-countries/country.js:59, e.g. misspelled or non-country names like 'Narnia' or 'Kanada'.","commonSituations":"Misspelled country names ('Geramny'); using partial/informal names the API does not match; stale cached name lists; passing localized names in another language.","solutions":["Check the spelling of the country name argument.","Use the official English country name (e.g. 'United States' not 'USA' variants the API may not match).","Catch EmptyResultError and offer the user a suggestion/fuzzy match flow.","If needed, query a different endpoint (e.g. /v3.1/translation/ or /v3.1/currency/) that matches the input you have."],"exampleFix":"// before\nawait countryCommand({ name: 'Kanada' });\n// after\nawait countryCommand({ name: 'Canada' });","handlingStrategy":"validation","validationCode":"if (typeof args.name !== 'string' || !args.name.trim()) {\n  throw new Error('country name must be a non-empty string');\n}","typeGuard":"function isNonEmptyString(v) { return typeof v === 'string' && v.trim().length > 0; }","tryCatchPattern":"try {\n  const countries = await countryCommand({ name });\n} catch (err) {\n  if (err instanceof EmptyResultError) return suggestSimilarNames(name);\n  throw err;\n}","preventionTips":["Normalize user input (trim, fix casing) before lookup.","Maintain a small alias map for informal names ('USA', 'UK').","Offer fuzzy-match suggestions when a name yields nothing.","Cache known-good names to avoid repeated misses."],"tags":["empty-result","rest-countries","api","validation"],"backgroundTag":"empty-result-set","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}