Reputation: 13335
I try to patch a library to catch [Errno 32] Broken pipe
.
The library is coded to run in Python 2 and Python 3. In Python 2 the exception is a
socket.error: [Errno 32] Broken pipe
in Python >= 3.3 it is a
BrokenPipeError: [Errno 32] Broken pipe
In Python 3.2 there is no BrokenPipeError
implemented. There is a socket.error
but it has quite a different description than in Python 2.
I have Debian Stretch installed on my system so it seems difficult to install Python 3.2 to check, which exception I would have to catch in this version. Still, I don't want to break the library in Python 3.2.
Therefore it would be very helpful if you could tell me which is the most specific exception to catch a broken pipe error in Python 3.2.
Upvotes: 3
Views: 399
Reputation: 6190
From the documentation you linked, it seems that you should catch socket.error. Then check if the .errno attrib is errno.EPIPE, if so then it's what you want, if not then re-raise the exception.
The subsequent error you linked to https://travis-ci.org/Mic92/python-mpd2/jobs/105030049 looks like it's caused by your test file https://github.com/Mic92/python-mpd2/blob/master/test.py#L42 mocking out the whole socket package (including socket.error). From a very quick look at the code, you might be OK to only mock out socket.socket
, and leave the rest as-is.
Upvotes: 1