Fix #120: Better error handling during file import

This commit is contained in:
Eliot Berriot 2018-03-25 15:44:48 +02:00
parent f1cf250e29
commit e99d757b57
No known key found for this signature in database
GPG key ID: DD6965E2476E5C27
3 changed files with 36 additions and 15 deletions

View file

@ -121,7 +121,13 @@ class Metadata(object):
def __init__(self, path):
self._file = mutagen.File(path)
self._conf = CONF[self.get_file_type(self._file)]
if self._file is None:
raise ValueError('Cannot parse metadata from {}'.format(path))
ft = self.get_file_type(self._file)
try:
self._conf = CONF[ft]
except KeyError:
raise ValueError('Unsupported format {}'.format(ft))
def get_file_type(self, f):
return f.__class__.__name__