{"record":{"id":"4d75c6a99d35fce8","repo":"RustPython/RustPython","slug":"multiple-exceptions","errorCode":null,"errorMessage":"Multiple exceptions: {}","messagePattern":"Multiple exceptions: (.+?)","errorType":"exception","errorClass":"OSError","httpStatus":null,"severity":"error","filePath":"Lib/asyncio/base_events.py","lineNumber":1176,"sourceCode":"                    happy_eyeballs_delay,\n                    loop=self,\n                ))[0]  # can't use sock, _, _ as it keeks a reference to exceptions\n\n            if sock is None:\n                exceptions = [exc for sub in exceptions for exc in sub]\n                try:\n                    if all_errors:\n                        raise ExceptionGroup(\"create_connection failed\", exceptions)\n                    if len(exceptions) == 1:\n                        raise exceptions[0]\n                    elif exceptions:\n                        # If they all have the same str(), raise one.\n                        model = str(exceptions[0])\n                        if all(str(exc) == model for exc in exceptions):\n                            raise exceptions[0]\n                        # Raise a combined exception so the user can see all\n                        # the various error messages.\n                        raise OSError('Multiple exceptions: {}'.format(\n                            ', '.join(str(exc) for exc in exceptions)))\n                    else:\n                        # No exceptions were collected, raise a timeout error\n                        raise TimeoutError('create_connection failed')\n                finally:\n                    exceptions = None\n\n        else:\n            if sock is None:\n                raise ValueError(\n                    'host and port was not specified and no sock specified')\n            if sock.type != socket.SOCK_STREAM:\n                # We allow AF_INET, AF_INET6, AF_UNIX as long as they\n                # are SOCK_STREAM.\n                # We support passing AF_UNIX sockets even though we have\n                # a dedicated API for that: create_unix_connection.\n                # Disallowing AF_UNIX in this method, breaks backwards\n                # compatibility.","sourceCodeStart":1158,"sourceCodeEnd":1194,"githubUrl":"https://github.com/RustPython/RustPython/blob/aaeab4f754b4f40efc0c8ab39cf7c4a3c35a8cfd/Lib/asyncio/base_events.py#L1158-L1194","documentation":"OSError raised by create_connection when all_errors is False (default), more than one address was tried, and the collected exceptions have differing str() representations. asyncio collapses identical failures into one but combines distinct messages into a single OSError prefixed 'Multiple exceptions: '.","triggerScenarios":"loop.create_connection(proto, host, port) against a dual-stack host where the IPv6 attempt gives 'Network is unreachable' and the IPv4 attempt gives 'Connection refused'; multiple A records with different per-address failures.","commonSituations":"Dual-stack clients on partially IPv6-capable networks; CDN hosts with several IPs where some are filtered; retry/monitoring logic that parses exception text instead of errno.","solutions":["Switch on exc.errno / exc.__context__ rather than parsing the combined message","Pass all_errors=True and handle the ExceptionGroup to get each failure separately","Constrain family= to the stack that works in your environment to reduce mixed failures"],"exampleFix":"# before\nexcept OSError as e:\n    if 'refused' in str(e): ...\n\n# after\nexcept OSError as e:\n    if e.errno == errno.ECONNREFUSED: ...\n# or per-attempt detail:\n#   await loop.create_connection(p, h, port, all_errors=True) + except*","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try:\n    tr, pr = await loop.create_connection(p, h, port)\nexcept OSError as e:\n    cause = e.__context__  # often holds the first underlying error\n    log.warning('connect failed errno=%s cause=%r', e.errno, cause)\n    raise","preventionTips":["Branch on errno, never on formatted message strings","Use all_errors=True when you need each attempt's failure individually","Log e.__context__ alongside the combined OSError for diagnosis"],"tags":["asyncio","network","oserror","connection","dual-stack"],"backgroundTag":"connection-failed","analyzedSha":"aaeab4f754b4f40efc0c8ab39cf7c4a3c35a8cfd","analyzedAt":"2026-08-17T00:37:52.100Z","schemaVersion":2},"datasetVersion":"2026-08-17T04:17:16.089Z"}