{"record":{"id":"5db56a24a220bdd2","repo":"OpenBB-finance/OpenBB","slug":"country-c-is-not-available-for-commodity-va","errorCode":null,"errorMessage":"Country '{c}' is not available for {commodity}. Valid countries: {valid_keys}","messagePattern":"Country '(.+?)' is not available for (.+?)\\. Valid countries: (.+?)","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"openbb_platform/providers/government_us/openbb_government_us/utils/psd_data_downloader.py","lineNumber":363,"sourceCode":"            if c.upper() in REGION_DISPLAY:\n                selected_region_codes.append(c.upper())\n                country_codes.append(c.upper())\n            # Check if it's a region name (includes \"european_union\" -> R05)\n            elif country_key in REGIONS:\n                region_code = REGIONS[country_key]\n                selected_region_codes.append(region_code)\n                country_codes.append(region_code)\n            # Check for \"eu\" shorthand -> treat as region R05\n            elif country_key == \"eu\":\n                selected_region_codes.append(\"R05\")\n                country_codes.append(\"R05\")\n            # Check if it's a country code\n            elif c.upper() in COUNTRY_TO_REGION:\n                code = c.upper()\n                # Validate against commodity-specific countries\n                if valid_country_codes and code not in valid_country_codes:\n                    valid_keys = get_valid_country_keys()\n                    raise ValueError(\n                        f\"Country '{c}' is not available for {commodity}. Valid countries: {valid_keys}\"\n                    )\n                selected_country_codes.append(code)\n                country_codes.append(code)\n            # Check if it's a country name (snake_case)\n            elif country_key in COUNTRIES:\n                code = COUNTRIES[country_key]\n                # Validate against commodity-specific countries\n                if valid_country_codes and code not in valid_country_codes:\n                    valid_keys = get_valid_country_keys()\n                    raise ValueError(\n                        f\"Country '{c}' is not available for {commodity}. Valid countries: {valid_keys}\"\n                    )\n                selected_country_codes.append(code)\n                country_codes.append(code)\n            else:\n                # Unknown country/region\n                valid_keys = sorted(","sourceCodeStart":345,"sourceCodeEnd":381,"githubUrl":"https://github.com/OpenBB-finance/OpenBB/blob/3e071fcc2cd9f891cac6040ae60296dba76dab46/openbb_platform/providers/government_us/openbb_government_us/utils/psd_data_downloader.py#L345-L381","documentation":"Country-validation ValueError from the ISO-code branch: the input matched a two-letter code in the global COUNTRY_TO_REGION map, but that code is not in the commodity-specific valid country set fetched from the metadata API (valid_country_codes). The message lists the full valid key set via get_valid_country_keys().","triggerScenarios":"Passing country='ZW' (or any ISO code) for a commodity the PSD database does not report for that country, e.g. a small country for a niche commodity.","commonSituations":"Region templates that pass a fixed country list to every commodity; users assuming worldwide coverage per commodity.","solutions":["Choose countries from the valid list in the error message (or the commodity's country metadata).","Use a region shorthand ('world', 'eu', region codes R00-R18) instead of unsupported individual countries.","Filter your country list against the commodity's available countries before calling."],"exampleFix":"# before\nfetch(commodity=\"cotton\", country=\"LU\")  # Luxembourg not reported\n\n# after\nfetch(commodity=\"cotton\", country=\"R15\")  # use the covering region","handlingStrategy":"validation","validationCode":"from openbb_government_us.utils.psd_data_downloader import (\n    COMMODITIES, _get_commodity_countries, COUNTRY_TO_REGION,\n)\n\ndef country_available(commodity: str, code: str) -> bool:\n    valid = set(_get_commodity_countries(COMMODITIES[commodity]).values())\n    return code.upper() in COUNTRY_TO_REGION and (not valid or code.upper() in valid)","typeGuard":"def is_iso_code_for_commodity(commodity: str, c: str) -> bool is not None and isinstance(c, str) and len(c) == 2 and c.upper() in COUNTRY_TO_REGION and country_available(commodity, c)","tryCatchPattern":null,"preventionTips":["Use region codes (R00-R18, 'world', 'eu') when individual countries are unsupported.","Cache the commodity's country metadata and validate selections against it."],"tags":["validation","psd","country","commodity"],"backgroundTag":null,"analyzedSha":"3e071fcc2cd9f891cac6040ae60296dba76dab46","analyzedAt":"2026-08-14T23:40:48.960Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}