diff --git a/src/smbprotocol/transport.py b/src/smbprotocol/transport.py index 052b43a..2288239 100644 --- a/src/smbprotocol/transport.py +++ b/src/smbprotocol/transport.py @@ -65,7 +65,7 @@ def connect(self): try: self._sock = socket.create_connection((self.server, self.port), timeout=self.timeout) except (OSError, socket.gaierror) as err: - raise ValueError(f"Failed to connect to '{self.server}:{self.port}'") from err + raise ValueError(f"Failed to connect to '{self.server}:{self.port}': {err}") from err self._sock.settimeout(None) # Make sure the socket is in blocking mode. self.connected = True diff --git a/tests/test_transport.py b/tests/test_transport.py index 960350c..0108dea 100644 --- a/tests/test_transport.py +++ b/tests/test_transport.py @@ -72,8 +72,15 @@ def test_normal_fail_message_too_big(self): ) def test_invalid_host(self): + """ + Raises ValueError when failing to connect to the remote server. + + The error message contains the low-level OS error details. + """ tcp = Tcp("fake-host", 445) - with pytest.raises(ValueError, match=re.escape("Failed to connect to 'fake-host:445'")): + # We just check for OSError marker, as the actual error message + # might be different based on current OS. + with pytest.raises(ValueError, match=r"Failed to connect to 'fake-host:445': \[Errno .*"): tcp.connect()