Skip to content

Commit

Permalink
Catch connection errors
Browse files Browse the repository at this point in the history
  • Loading branch information
dbrgn committed Nov 12, 2014
1 parent 0e323a2 commit 4e82650
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions orochi/backends/mpd.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@
"""
from __future__ import print_function, division, absolute_import, unicode_literals

import contextlib
import functools
import logging
import os
import select
import socket
import threading
import functools
import logging
import contextlib

import mpd

Expand Down Expand Up @@ -151,11 +152,17 @@ def connection(self):
Context manager to connect to and disconnect from MPD.
"""
try:
self.client.connect(self.host, self.port)
try:
self.client.connect(self.host, self.port)
except (mpd.ConnectionError, socket.error) as e:
raise errors.InitializationError('Could not connect to mpd: %s' % e)
yield
finally:
self.client.close()
self.client.disconnect()
try:
self.client.close()
self.client.disconnect()
except mpd.ConnectionError:
pass

@catch_mpd_error('Could not load & play song.')
def load(self, path):
Expand Down

0 comments on commit 4e82650

Please sign in to comment.