From a046551304d55689a2512b2c833496eed6291cf9 Mon Sep 17 00:00:00 2001 From: Adrian Sampson Date: Thu, 9 Jan 2014 12:07:08 -0800 Subject: [PATCH] handle some exceptions while writing during import A few people get freaky crashes at this point, even though it theoretically should be impossible (since reading the file succeeded earlier). This should help the import process not croak at that point. --- beets/importer.py | 14 +++++++++++--- docs/changelog.rst | 2 ++ 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/beets/importer.py b/beets/importer.py index fbb5a19de..9ef949e63 100644 --- a/beets/importer.py +++ b/beets/importer.py @@ -30,7 +30,7 @@ from beets import config from beets.util import pipeline from beets.util import syspath, normpath, displayable_path from beets.util.enumeration import enum -from beets.mediafile import UnreadableFileError +from beets import mediafile action = enum( 'SKIP', 'ASIS', 'TRACKS', 'MANUAL', 'APPLY', 'MANUAL_ID', @@ -560,7 +560,7 @@ def read_tasks(session): not os.path.isdir(syspath(toppath)): try: item = library.Item.from_path(toppath) - except UnreadableFileError: + except mediafile.UnreadableFileError: log.warn(u'unreadable file: {0}'.format( util.displayable_path(toppath) )) @@ -867,7 +867,15 @@ def manipulate_files(session): item.move(True) if config['import']['write'] and task.should_write_tags(): - item.write() + try: + item.write() + except mediafile.UnreadableFileError as exc: + log.error(u'error while writing ({0}): {0}'.format( + exc, + util.displayable_path(item.path) + )) + except util.FilesystemError as exc: + exc.log(log) # Save new paths. with session.lib.transaction(): diff --git a/docs/changelog.rst b/docs/changelog.rst index 3b247550e..c17d91670 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -23,6 +23,8 @@ Other little fixes: Thanks to Heinz Wiesinger. * Fix Python 2.6 compatibility in some logging statements in :doc:`/plugins/chroma` and :doc:`/plugins/lastgenre`. +* Prevent some crashes when things go really wrong when writing file metadata + at the end of the import process. 1.3.2 (December 22, 2013)