Convert a socket.error to ConnectionFailure and raise it.
(
address: Any,
error: Exception,
msg_prefix: Optional[str] = None,
timeout_details: Optional[dict[str, float]] = None,
)
| 122 | |
| 123 | |
| 124 | def _raise_connection_failure( |
| 125 | address: Any, |
| 126 | error: Exception, |
| 127 | msg_prefix: Optional[str] = None, |
| 128 | timeout_details: Optional[dict[str, float]] = None, |
| 129 | ) -> NoReturn: |
| 130 | """Convert a socket.error to ConnectionFailure and raise it.""" |
| 131 | host, port = address |
| 132 | # If connecting to a Unix socket, port will be None. |
| 133 | if port is not None: |
| 134 | msg = "%s:%d: %s" % (host, port, error) |
| 135 | else: |
| 136 | msg = f"{host}: {error}" |
| 137 | if msg_prefix: |
| 138 | msg = msg_prefix + msg |
| 139 | if "configured timeouts" not in msg: |
| 140 | msg += format_timeout_details(timeout_details) |
| 141 | if ( |
| 142 | isinstance(error, socket.timeout) |
| 143 | or isinstance(error, SSLErrors) |
| 144 | and "timed out" in str(error) |
| 145 | ): |
| 146 | raise NetworkTimeout(msg) from error |
| 147 | else: |
| 148 | raise AutoReconnect(msg) from error |
| 149 | |
| 150 | |
| 151 | class _CancellationContext: |
no test coverage detected