From 59dd30e987a1acfb39296a3ab2a65461f0df4933 Mon Sep 17 00:00:00 2001 From: Adi Roiban Date: Fri, 26 Jan 2024 13:15:14 +0000 Subject: [PATCH] Initial fix. --- src/smbprotocol/transport.py | 2 +- tests/test_transport.py | 9 ++++++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/smbprotocol/transport.py b/src/smbprotocol/transport.py index 052b43a4..22882394 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 960350ca..0108dea5 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()