mirror of
https://github.com/beetbox/beets.git
synced 2026-01-05 15:33:15 +01:00
FileOperationError: include underlying exception
A primitive form of Python 3's "exception chaining", which is what we really want here. Someday...
This commit is contained in:
parent
3c8decc487
commit
3a26845f5e
1 changed files with 15 additions and 3 deletions
|
|
@ -265,6 +265,18 @@ class FileOperationError(Exception):
|
|||
Possibilities include an unsupported media type, a permissions
|
||||
error, and an unhandled Mutagen exception.
|
||||
"""
|
||||
def __init__(self, reason):
|
||||
"""Create an exception with the underlying (chained) exception
|
||||
`reason`.
|
||||
"""
|
||||
super(FileOperationError, self).__init__(reason)
|
||||
self.reason = reason
|
||||
|
||||
def __str__(self):
|
||||
"""Get a string representing the error. Uses the same string as
|
||||
the underlying reason.
|
||||
"""
|
||||
return str(self.reason)
|
||||
|
||||
|
||||
class ReadError(FileOperationError):
|
||||
|
|
@ -372,7 +384,7 @@ class Item(LibModel):
|
|||
try:
|
||||
f = MediaFile(syspath(read_path))
|
||||
except (OSError, IOError) as exc:
|
||||
raise ReadError(str(exc))
|
||||
raise ReadError(exc)
|
||||
|
||||
for key in ITEM_KEYS_META:
|
||||
value = getattr(f, key)
|
||||
|
|
@ -399,7 +411,7 @@ class Item(LibModel):
|
|||
try:
|
||||
f = MediaFile(syspath(self.path))
|
||||
except (OSError, IOError) as exc:
|
||||
raise ReadError(str(exc))
|
||||
raise ReadError(exc)
|
||||
|
||||
plugins.send('write', item=self)
|
||||
|
||||
|
|
@ -408,7 +420,7 @@ class Item(LibModel):
|
|||
try:
|
||||
f.save(id3v23=beets.config['id3v23'].get(bool))
|
||||
except (OSError, IOError, MutagenError) as exc:
|
||||
raise WriteError(str(exc))
|
||||
raise WriteError(exc)
|
||||
|
||||
# The file has a new mtime.
|
||||
self.mtime = self.current_mtime()
|
||||
|
|
|
|||
Loading…
Reference in a new issue