hide buggy/unhandled Mutagen exceptions

This commit is contained in:
Adrian Sampson 2011-08-02 11:22:26 -07:00
parent bbf2e65154
commit 7220f1a852
2 changed files with 12 additions and 0 deletions

1
NEWS
View file

@ -1,5 +1,6 @@
1.0b10
------
* Handle exceptions thrown when running Mutagen.
* Fix a missing __future__ import in embedart on Python 2.5.
* Fix ID3 and MPEG-4 tag names for the album-artist field.
* Fix Unicode encoding of album artist, album type, and label.

View file

@ -39,11 +39,17 @@ import re
import base64
import imghdr
import os
import logging
import traceback
from beets.util.enumeration import enum
__all__ = ['UnreadableFileError', 'FileTypeError', 'MediaFile']
# Logger.
log = logging.getLogger('beets')
# Exceptions.
# Raised for any file MediaFile can't read.
@ -630,9 +636,14 @@ class MediaFile(object):
try:
self.mgfile = mutagen.File(path)
except unreadable_exc:
log.warn('header parsing failed')
raise UnreadableFileError('Mutagen could not read file')
except IOError:
raise UnreadableFileError('could not read file')
except:
# Hide bugs in Mutagen.
log.error('uncaught Mutagen exception:\n' + traceback.format_exc())
raise UnreadableFileError('Mutagen raised an exception')
if self.mgfile is None: # Mutagen couldn't guess the type
raise FileTypeError('file type unsupported by Mutagen')