]> kaliko git repositories - python-musicpd.git/commitdiff
Fixed ConnectionError argument
authorKaliko Jack <kaliko@azylum.org>
Tue, 6 Feb 2024 17:30:49 +0000 (18:30 +0100)
committerKaliko Jack <kaliko@azylum.org>
Tue, 6 Feb 2024 17:30:49 +0000 (18:30 +0100)
Timeout does not expose errno, strerror attributes

musicpd.py
test.py

index d8dc01b9048510a5b93ae00f652c5471e2674259..e6b1c05b44829f33abdb46e4e99a113f8d62276d 100644 (file)
@@ -648,7 +648,7 @@ class MPDClient:
             sock.connect(path)
             sock.settimeout(self.socket_timeout)
         except socket.error as socket_err:
-            raise ConnectionError(socket_err.strerror) from socket_err
+            raise ConnectionError(socket_err) from socket_err
         return sock
 
     def _connect_tcp(self, host, port):
@@ -662,7 +662,7 @@ class MPDClient:
                                      socket.SOCK_STREAM, socket.IPPROTO_TCP,
                                      flags)
         except socket.error as gaierr:
-            raise ConnectionError(gaierr.strerror) from gaierr
+            raise ConnectionError(gaierr) from gaierr
         for res in gai:
             af, socktype, proto, _, sa = res
             sock = None
@@ -674,12 +674,12 @@ class MPDClient:
                 sock.settimeout(self.socket_timeout)
                 return sock
             except socket.error as socket_err:
-                log.debug('opening socket %s failed: %s}', sa, socket_err)
+                log.debug('opening socket %s failed: %s', sa, socket_err)
                 err = socket_err
                 if sock is not None:
                     sock.close()
         if err is not None:
-            raise ConnectionError(err.strerror)
+            raise ConnectionError(err)
         raise ConnectionError("getaddrinfo returns an empty list")
 
     def noidle(self):
diff --git a/test.py b/test.py
index a123b306fcdfd58df0d06e6370bf192c9c8bcce6..299b54a85669c4fa6574d911e90da45ac3cee304 100755 (executable)
--- a/test.py
+++ b/test.py
@@ -633,7 +633,7 @@ class TestConnectionError(unittest.TestCase):
         cli = musicpd.MPDClient()
         with self.assertRaises(musicpd.ConnectionError) as cme:
             cli.connect()
-        self.assertEqual('err 42', str(cme.exception))
+        self.assertEqual('[Errno 42] err 42', str(cme.exception))
 
     def test_non_available_unix_socket(self):
         delattr(musicpd.socket, 'AF_UNIX')
@@ -651,7 +651,7 @@ class TestConnectionError(unittest.TestCase):
         cli = musicpd.MPDClient()
         with self.assertRaises(musicpd.ConnectionError) as cme:
             cli.connect(host=TEST_MPD_HOST)
-        self.assertEqual('gaierr 42', str(cme.exception))
+        self.assertEqual('[Errno 42] gaierr 42', str(cme.exception))
 
     @mock.patch('socket.getaddrinfo')
     @mock.patch('socket.socket')
@@ -665,7 +665,7 @@ class TestConnectionError(unittest.TestCase):
         cli = musicpd.MPDClient()
         with self.assertRaises(musicpd.ConnectionError) as cme:
             cli.connect(host=TEST_MPD_HOST)
-        self.assertEqual('tcp conn err 42', str(cme.exception))
+        self.assertEqual('[Errno 42] tcp conn err 42', str(cme.exception))
 
     @mock.patch('socket.getaddrinfo')
     def test_connect_tcp_connect_empty_gai(self, gai_mock):