{"record":{"id":"d59367513aa915b5","repo":"OpenBB-finance/OpenBB","slug":"error-fetching-port-data-result-result-args","errorCode":null,"errorMessage":"Error fetching port data: {result} -> {result.args[0]}","messagePattern":"Error fetching port data: (.+?) -> (.+?)","errorType":"exception","errorClass":"OpenBBError","httpStatus":null,"severity":"error","filePath":"openbb_platform/providers/imf/openbb_imf/models/port_volume.py","lineNumber":446,"sourceCode":"            \"\"\"Fetch data for a single port.\"\"\"\n            try:\n                data = await get_daily_port_activity_data(\n                    port_code, query.start_date, query.end_date\n                )\n                if data:\n                    output.extend(data)\n            except Exception as e:\n                raise OpenBBError(\n                    f\"Failed to fetch data for port {port_code}: {e} -> {e.args}\"\n                ) from e\n\n        tasks = [fetch_port_data(port_code=port_code) for port_code in port_codes]\n\n        tasks_results = await asyncio.gather(*tasks, return_exceptions=True)\n\n        for result in tasks_results:\n            if isinstance(result, Exception):\n                raise OpenBBError(\n                    f\"Error fetching port data: {result} -> {result.args[0]}\"\n                )\n\n        if not output:\n            raise OpenBBError(\n                f\"No data found for the specified port(s). {port_codes}\"\n                \" Ensure the port_code is correct and available in the IMF PortWatch dataset.\"\n            )\n        return output\n\n    @staticmethod\n    def transform_data(\n        query: ImfPortVolumeQueryParams,\n        data: list,\n        **kwargs: Any,\n    ) -> list[ImfPortVolumeData]:\n        \"\"\"Transform the raw data into the model.\"\"\"\n        return [","sourceCodeStart":428,"sourceCodeEnd":464,"githubUrl":"https://github.com/OpenBB-finance/OpenBB/blob/3e071fcc2cd9f891cac6040ae60296dba76dab46/openbb_platform/providers/imf/openbb_imf/models/port_volume.py#L428-L464","documentation":"Aggregation error after asyncio.gather(..., return_exceptions=True): at least one fetch_port_data task returned an exception object instead of data. The code iterates the results and re-raises the first exception wrapped in OpenBBError, exposing result and result.args[0]. It is the outer half of error 584 — the same underlying per-port failure, but surfaced from the gather loop when the inner wrapper itself propagated as the task's exception.","triggerScenarios":"One or more ports in a multi-port request failing (network, timeout, invalid response) while gather collects exceptions instead of aborting; the first failing result in tasks_results order determines the message.","commonSituations":"Large multi-port batches where any single port failure kills the entire response; intermittent IMF API errors; scripts that need all-or-nothing semantics but want the offending port identified.","solutions":["Retry the whole request, or split port_codes into batches so a single bad port does not discard successful results.","Extract the failing port from the message ('Error fetching port data: Failed to fetch data for port <id>') and retry without it if partial data is acceptable.","Check result.args[0] content: HTTP status text points to server-side issues (retry later), parse errors point to API contract changes (update the provider package)."],"exampleFix":"# before\nres = await obb.economy.port_volume(provider='imf', port_code=all_ports)\n\n# after (batched, keep successes)\nresults = []\nfor batch in chunks(all_ports, 5):\n    try:\n        results.append(await obb.economy.port_volume(provider='imf', port_code=','.join(batch)))\n    except OpenBBError as e:\n        print(f'skipping failed batch {batch}: {e}')","handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"ok, failed = [], []\nfor batch in chunks(port_codes, 5):\n    try:\n        ok.append(await obb.economy.port_volume(provider='imf', port_code=','.join(batch)))\n    except OpenBBError as e:\n        if 'Error fetching port data' in str(e):\n            failed.append((batch, str(e)))\n        else:\n            raise\n# proceed with ok, report failed","preventionTips":["Small batches prevent all-or-nothing loss on multi-port requests.","Parse the failing port out of the message to retry or drop it selectively.","Distinguish this (any task failed) from error 586 (all tasks succeeded, no data)."],"tags":["network","retry","imf","ports","async","error-aggregation"],"backgroundTag":null,"analyzedSha":"3e071fcc2cd9f891cac6040ae60296dba76dab46","analyzedAt":"2026-08-14T23:40:48.960Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}