Skip to content

Commit

Permalink
Initial fix. (#264)
Browse files Browse the repository at this point in the history
  • Loading branch information
adiroiban authored Jan 27, 2024
1 parent b4ce482 commit 2cfd6b5
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/smbprotocol/transport.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
9 changes: 8 additions & 1 deletion tests/test_transport.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()


Expand Down

0 comments on commit 2cfd6b5

Please sign in to comment.