Skip to content

Commit c1369ca

Browse files
committed
Revert "more readable exception handling _connect_tcp()"
This reverts commit da8cb1a. It turned out that da8cb1 actually changed the API of python-mpd: if an error occurred while connecting to the MPD server, MPDClient._connect_tcp() would always return 'ConnectionError("getaddrinfo returns an empty list"), even if getaddrinfo() actually returned something. I have no idea how to make getaddrinfo() returns nothing, so it's hard to test at the moment. Conflicts: test.py
1 parent 08e2da8 commit c1369ca

2 files changed

Lines changed: 3 additions & 9 deletions

File tree

mpd.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -395,11 +395,11 @@ def _connect_tcp(self, host, port):
395395
err = e
396396
if sock is not None:
397397
sock.close()
398+
if err is not None:
399+
raise err
398400
else:
399401
raise ConnectionError("getaddrinfo returns an empty list")
400402

401-
raise err
402-
403403
def connect(self, host, port):
404404
if self._sock is not None:
405405
raise ConnectionError("Already connected")

test.py

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ def setUpClass(self):
3333
self.client.connect(MPD_HOST, MPD_PORT)
3434
self.idleclient.connect(MPD_HOST, MPD_PORT)
3535
self.commands = self.client.commands()
36-
except (mpd.ConnectionError, SocketError) as e:
36+
except SocketError as e:
3737
raise Exception("Can't connect mpd! Start it or check the configuration: %s" % e)
3838
if MPD_PASSW != None:
3939
try:
@@ -129,12 +129,6 @@ def test_client_to_client(self):
129129
channels = self.client.channels()
130130
self.assertNotIn("monty", channels)
131131

132-
def test_connection_error(self):
133-
client2 = mpd.MPDClient()
134-
with self.assertRaises(mpd.ConnectionError) as cm:
135-
# should never return getaddrinfo
136-
client2.connect("255.255.255.255", 6600)
137-
138132
def test_commands_list(self):
139133
"""
140134
Test if all implemented commands are valid

0 commit comments

Comments
 (0)