mirror of
https://github.com/beetbox/beets.git
synced 2025-12-15 21:14:19 +01:00
human-readable errors in read() and write()
This commit is contained in:
parent
e1f75e8e91
commit
bf78751090
4 changed files with 18 additions and 9 deletions
|
|
@ -320,11 +320,9 @@ class Item(object):
|
|||
read_path = normpath(read_path)
|
||||
try:
|
||||
f = MediaFile(syspath(read_path))
|
||||
except Exception:
|
||||
log.debug(u'failed reading file: {0}'.format(
|
||||
displayable_path(read_path))
|
||||
)
|
||||
raise
|
||||
except (OSError, IOError) as exc:
|
||||
raise util.FilesystemError(exc, 'read', (self.path,),
|
||||
traceback.format_exc())
|
||||
|
||||
for key in ITEM_KEYS_META:
|
||||
setattr(self, key, getattr(f, key))
|
||||
|
|
@ -340,7 +338,12 @@ class Item(object):
|
|||
"""
|
||||
plugins.send('write', item=self)
|
||||
|
||||
f = MediaFile(syspath(self.path))
|
||||
try:
|
||||
f = MediaFile(syspath(self.path))
|
||||
except (OSError, IOError) as exc:
|
||||
raise util.FilesystemError(exc, 'read', (self.path,),
|
||||
traceback.format_exc())
|
||||
|
||||
for key in ITEM_KEYS_WRITABLE:
|
||||
setattr(f, key, getattr(self, key))
|
||||
|
||||
|
|
|
|||
|
|
@ -59,6 +59,10 @@ log = logging.getLogger('beets')
|
|||
class UnreadableFileError(IOError):
|
||||
pass
|
||||
|
||||
class FileIOError(UnreadableFileError, IOError):
|
||||
def __init__(self, exc):
|
||||
IOError.__init__(self, exc.errno, exc.strerror, exc.filename)
|
||||
|
||||
# Raised for files that don't seem to have a type MediaFile supports.
|
||||
class FileTypeError(UnreadableFileError):
|
||||
pass
|
||||
|
|
@ -864,8 +868,8 @@ class MediaFile(object):
|
|||
except unreadable_exc as exc:
|
||||
log.debug(u'header parsing failed: {0}'.format(unicode(exc)))
|
||||
raise UnreadableFileError('Mutagen could not read file')
|
||||
except IOError:
|
||||
raise UnreadableFileError('could not read file')
|
||||
except IOError as exc:
|
||||
raise FileIOError(exc)
|
||||
except Exception as exc:
|
||||
# Hide bugs in Mutagen.
|
||||
log.debug(traceback.format_exc())
|
||||
|
|
|
|||
|
|
@ -97,7 +97,7 @@ class FilesystemError(HumanReadableException):
|
|||
clause = 'while {0} {1} to {2}'.format(
|
||||
self._gerund(), repr(self.paths[0]), repr(self.paths[1])
|
||||
)
|
||||
elif self.verb in ('delete', 'write', 'create'):
|
||||
elif self.verb in ('delete', 'write', 'create', 'read'):
|
||||
clause = 'while {0} {1}'.format(
|
||||
self._gerund(), repr(self.paths[0])
|
||||
)
|
||||
|
|
|
|||
|
|
@ -31,6 +31,8 @@ Changelog
|
|||
* The :ref:`fields-cmd` command shows template fields provided by plugins.
|
||||
Thanks again to Pedro Silva.
|
||||
* Album art filenames now respect the :ref:`replace` configuration.
|
||||
* Friendly error messages are now printed when trying to read or write files
|
||||
that go missing.
|
||||
|
||||
1.1.0 (April 29, 203)
|
||||
---------------------
|
||||
|
|
|
|||
Loading…
Reference in a new issue