{"record":{"id":"4ab1129227abd577","repo":"OpenBB-finance/OpenBB","slug":"invalid-chokepoint-name-chokepoint-expected-on","errorCode":null,"errorMessage":"Invalid chokepoint name: {chokepoint}. Expected one of {list(CHOKEPOINTS_NAME_TO_ID.keys())}.","messagePattern":"Invalid chokepoint name: (.+?)\\. Expected one of (.+?)\\.","errorType":"validation","errorClass":"OpenBBError","httpStatus":null,"severity":"error","filePath":"openbb_platform/providers/imf/openbb_imf/models/maritime_chokepoint_volume.py","lineNumber":324,"sourceCode":"        async def get_one(chokepoint_id):\n            \"\"\"Get data for a single chokepoint.\"\"\"\n            data = await get_daily_chokepoint_data(\n                chokepoint_id, query.start_date, query.end_date\n            )\n            if data:\n                results.extend(data)\n\n        # Accept both keys and values from CHOKEPOINTS_NAME_TO_ID\n        chokepoint_ids: list = []\n        for chokepoint in chokepoints:\n            if chokepoint in CHOKEPOINTS_NAME_TO_ID:\n                chokepoint_ids.append(CHOKEPOINTS_NAME_TO_ID[chokepoint])\n            elif chokepoint in CHOKEPOINTS_NAME_TO_ID.values() or chokepoint.startswith(\n                \"chokepoint\"\n            ):\n                chokepoint_ids.append(chokepoint)\n            else:\n                raise OpenBBError(\n                    f\"Invalid chokepoint name: {chokepoint}. Expected one of {list(CHOKEPOINTS_NAME_TO_ID.keys())}.\"\n                )\n\n        tasks = [\n            get_one(chokepoint_id) for chokepoint_id in chokepoint_ids if chokepoint_id\n        ]\n\n        task_results = await asyncio.gather(*tasks, return_exceptions=True)\n\n        for task_result in task_results:\n            if isinstance(task_result, Exception):\n                raise OpenBBError(task_result)\n\n        if not results:\n            raise OpenBBError(\"The response was returned empty with no error message.\")\n\n        return results\n","sourceCodeStart":306,"sourceCodeEnd":342,"githubUrl":"https://github.com/OpenBB-finance/OpenBB/blob/3e071fcc2cd9f891cac6040ae60296dba76dab46/openbb_platform/providers/imf/openbb_imf/models/maritime_chokepoint_volume.py#L306-L342","documentation":"Second-layer validation in the chokepoint volume fetcher: while mapping user tokens to ids, a token that is neither a CHOKEPOINTS_NAME_TO_ID key, a value, nor a 'chokepoint'-prefixed string raises here. It complements the Pydantic validator by also rejecting strings like 'chokepoint99' that merely start with 'chokepoint' but pass the earlier isinstance checks (e.g. list inputs bypass strict name checking in the validator).","triggerScenarios":"Passing a list of chokepoints containing an unknown token (lists are filtered, not validated, upstream); or a comma string that slipped through with a 'chokepointX' style value not in the map (any 'chokepoint'-prefixed string is accepted downstream, then fails in the actual fetch); or values that bypass field validation.","commonSituations":"Programmatic list inputs built from user data without sanitization; passing 'chokepoint25' or arbitrary 'chokepoint<text>' strings; direct QueryParams construction skipping validators.","solutions":["Sanitize every token against CHOKEPOINTS_NAME_TO_ID keys/values before building the query.","Use only documented chokepointN ids with N in 1..24.","Prefer comma-separated validated strings over raw lists so the field validator runs."],"exampleFix":"# before\nmaritime_chokepoint_volume(chokepoint=['Strait of Hormuz', 'chokepoint99'])\n\n# after\nmaritime_chokepoint_volume(chokepoint=['Strait of Hormuz', 'chokepoint7'])","handlingStrategy":"validation","validationCode":"import re\nfrom openbb_imf.models.maritime_chokepoint_volume import CHOKEPOINTS_NAME_TO_ID\nVALID = set(CHOKEPOINTS_NAME_TO_ID) | set(CHOKEPOINTS_NAME_TO_ID.values())\ndef clean(tokens):\n    ok = []\n    for t in tokens:\n        t = t.strip()\n        if t in VALID or re.fullmatch(r'chokepoint([1-9]|1[0-9]|2[0-4])', t):\n            ok.append(t)\n        else:\n            raise ValueError(f'unknown chokepoint: {t}')\n    return ok","typeGuard":"import re\ndef is_valid_chokepoint_token(t: str) -> bool:\n    return (t in CHOKEPOINTS_NAME_TO_ID\n            or t in CHOKEPOINTS_NAME_TO_ID.values()\n            or re.fullmatch(r'chokepoint([1-9]|1[0-9]|2[0-4])', t) is not None)","tryCatchPattern":null,"preventionTips":["Never pass unsanitized user strings as chokepoint lists","Regex-validate chokepointN ids against 1..24"],"tags":["imf","portwatch","validation","chokepoint"],"backgroundTag":null,"analyzedSha":"3e071fcc2cd9f891cac6040ae60296dba76dab46","analyzedAt":"2026-08-14T23:40:48.960Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}