{"record":{"id":"114166419ff2056d","repo":"OpenBB-finance/OpenBB","slug":"country-value-cannot-be-empty","errorCode":null,"errorMessage":"Country value cannot be empty.","messagePattern":"Country value cannot be empty\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"openbb_platform/providers/imf/openbb_imf/utils/dot_helpers.py","lineNumber":84,"sourceCode":"    (e.g., 'united_states'). Returns the ISO code.\n\n    Parameters\n    ----------\n    value : str\n        Country code or name to resolve.\n\n    Returns\n    -------\n    str\n        The resolved ISO country code.\n\n    Raises\n    ------\n    ValueError\n        If the input cannot be resolved to a valid country code.\n    \"\"\"\n    if not value:\n        raise ValueError(\"Country value cannot be empty.\")\n\n    # Handle wildcards\n    if value.lower() in [\"all\", \"*\"]:\n        return \"*\"\n\n    # Common aliases for frequently used regions\n    common_aliases = {\n        \"world\": \"G001\",\n        \"euro_area\": \"G163\",\n        \"eurozone\": \"G163\",\n        \"eu\": \"G998\",\n        \"european_union\": \"G998\",\n        \"europe\": \"GX170\",\n    }\n\n    v_lower = value.lower().replace(\" \", \"_\")\n\n    # Check common aliases first","sourceCodeStart":66,"sourceCodeEnd":102,"githubUrl":"https://github.com/OpenBB-finance/OpenBB/blob/3e071fcc2cd9f891cac6040ae60296dba76dab46/openbb_platform/providers/imf/openbb_imf/utils/dot_helpers.py#L66-L102","documentation":"Raised at the top of the country-resolution helper in dot_helpers.py when the incoming value is falsy (empty string, None after strip, empty list item). The function maps user-friendly country input to IMF SDMX area codes, and an empty input cannot map to anything, so it fails fast instead of sending an invalid query to the IMF API.","triggerScenarios":"Calling a DOT/IMTS helper with country='' or None; a list of countries containing an empty entry (['USA', '']); stripping user input to '' before passing it in.","commonSituations":"Form fields left blank; CSV/config rows with missing country columns; loops that pass variables which are conditionally set and sometimes remain None.","solutions":["Supply a non-empty country: ISO3 code ('USA') or snake_case name ('united_states').","Filter empty entries out of lists before calling: [c for c in countries if c and c.strip()].","Use '*' or 'all' when the intent is 'every country' — the helper maps those to the wildcard."],"exampleFix":"# before\ncountries = ['USA', '', 'DEU']\nres = imts_query(country=countries, counterpart='all', indicator='TXG_FOB_USD')\n\n# after\ncountries = [c for c in ['USA', '', 'DEU'] if c]\nres = imts_query(country=countries, counterpart='all', indicator='TXG_FOB_USD')","handlingStrategy":"validation","validationCode":"countries = [c.strip() for c in (countries or []) if c and c.strip()]\nif not countries:\n    raise ValueError('At least one country is required.')\nres = imts_query(country=countries, counterpart='*', indicator='TXG_FOB_USD')","typeGuard":"def is_non_empty_country(value: str | list[str] | None) -> bool:\n    if value is None:\n        return False\n    items = [value] if isinstance(value, str) else value\n    return any(isinstance(i, str) and i.strip() for i in items)","tryCatchPattern":"try:\n    code = transform_country(raw)\nexcept ValueError as e:\n    if 'cannot be empty' in str(e):\n        raise ValueError(f'Country field is required, got: {raw!r}') from e\n    raise","preventionTips":["Filter blank strings out of country lists before calling.","Make country fields required in your forms/schemas.","Use '*'/'all' for wildcard intent instead of empty values."],"tags":["validation","imf","country-codes","dot","parameters"],"backgroundTag":null,"analyzedSha":"3e071fcc2cd9f891cac6040ae60296dba76dab46","analyzedAt":"2026-08-14T23:40:48.960Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}