diff --git a/beetsplug/embedart.py b/beetsplug/embedart.py index 4e56b569d..612fcc5b2 100644 --- a/beetsplug/embedart.py +++ b/beetsplug/embedart.py @@ -32,7 +32,12 @@ def _embed(path, items, maxwidth=0): if maxwidth: path = ArtResizer.shared.resize(maxwidth, syspath(path)) - data = open(syspath(path), 'rb').read() + try: + with open(syspath(path), 'rb') as f: + data = f.read() + except IOError as exc: + log.error(u'embedart: could not read image file: {0}'.format(exc)) + return image = mediafile.Image(data, type=mediafile.ImageType.front) # Add art to each file. @@ -41,7 +46,7 @@ def _embed(path, items, maxwidth=0): for item in items: try: f = mediafile.MediaFile(syspath(item.path)) - except mediafile.UnreadableFileError as exc: + except (mediafile.UnreadableFileError, IOError) as exc: log.warn('Could not embed art in {0}: {1}'.format( displayable_path(item.path), exc )) diff --git a/docs/changelog.rst b/docs/changelog.rst index e84a57be3..3694a034a 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -22,6 +22,7 @@ Fixes: and the library includes the converted item. * The importer now logs a message instead of crashing when errors occur while opening the files to be imported. +* :doc:`/plugins/embedart`: Better error messages in exceptional conditions. .. _enum34: https://pypi.python.org/pypi/enum34 .. _enum: https://docs.python.org/3.4/library/enum.html