From 4dcbb38d789292450c5b607062045dd68219222f Mon Sep 17 00:00:00 2001 From: Adrian Sampson Date: Sat, 3 Jul 2010 23:55:27 -0700 Subject: [PATCH] log a warning instead of silently ignoring corrupt files --- NEWS | 2 ++ beets/autotag/__init__.py | 7 +++++-- beets/ui.py | 11 +++++++---- 3 files changed, 14 insertions(+), 6 deletions(-) diff --git a/NEWS b/NEWS index 2ad27e566..c6f5f0a1f 100644 --- a/NEWS +++ b/NEWS @@ -14,6 +14,8 @@ support UTF-8. * Importing without autotagging ("beet import -A") is now faster and doesn't print out a bunch of whitespace. +* The importer now logs an error instead of crashing when it attempts + to read a corrupt file. 1.0b1 ----- diff --git a/beets/autotag/__init__.py b/beets/autotag/__init__.py index 59c348efd..ae75ccaa0 100644 --- a/beets/autotag/__init__.py +++ b/beets/autotag/__init__.py @@ -21,6 +21,7 @@ from beets.autotag import mb import re from munkres import Munkres from beets import library, mediafile +import logging # Try 5 releases. In the future, this should be more dynamic: let the # probability of continuing to the next release be inversely @@ -62,6 +63,9 @@ class AutotagError(Exception): class InsufficientMetadataError(AutotagError): pass +# Global logger. +log = logging.getLogger('beets') + def _first_n(it, n): """Takes an iterator and returns another iterator, trunacted to yield only the first n elements. @@ -112,8 +116,7 @@ def albums_in_dir(path): except mediafile.FileTypeError: pass except mediafile.UnreadableFileError: - #FIXME log an error - pass + log.warn('unreadable file: ' + filename) else: items.append(i) diff --git a/beets/ui.py b/beets/ui.py index 449043c4a..c71e52078 100644 --- a/beets/ui.py +++ b/beets/ui.py @@ -18,9 +18,12 @@ import locale from beets import autotag from beets import library -from beets.mediafile import FileTypeError +from beets.mediafile import UnreadableFileError, FileTypeError from beets.player import bpd +# Global logger. +log = logging.getLogger('beets') + # Utilities. def _print(txt=''): @@ -356,9 +359,9 @@ def import_files(lib, paths, copy=True, write=True, autot=True, logpath=None): item = library.Item.from_path(filepath) except FileTypeError: continue - except mediafile.UnreadableFileError: - #FIXME log an error - pass + except UnreadableFileError: + log.warn('unreadable file: ' + filepath) + continue # Add the item to the library, copying if requested. if copy: