PICARD-2662: display a more explicit message on Mutagen errors (#2245)

* PICARD-2662: display a more explicit message on Mutagen errors

* MUTAGEN -> PARSER
This commit is contained in:
Laurent Monin
2023-06-26 14:56:55 +02:00
committed by GitHub
parent 203aa6bd4a
commit fa5e24f1ec

View File

@@ -56,6 +56,8 @@ import re
import shutil
import time
from mutagen._util import MutagenError
from PyQt5 import QtCore
from picard import (
@@ -106,6 +108,7 @@ class FileErrorType(Enum):
UNKNOWN = auto()
NOTFOUND = auto()
NOACCESS = auto()
PARSER = auto()
class File(QtCore.QObject, Item):
@@ -205,13 +208,16 @@ class File(QtCore.QObject, Item):
def _set_error(self, error):
self.state = File.ERROR
self.error_append(str(error))
if any_exception_isinstance(error, FileNotFoundError):
if any_exception_isinstance(error, MutagenError):
self.error_type = FileErrorType.PARSER
self.error_append(_('The file failed to parse, either the file is damaged or has an unsupported file format.'))
elif any_exception_isinstance(error, FileNotFoundError):
self.error_type = FileErrorType.NOTFOUND
elif any_exception_isinstance(error, PermissionError):
self.error_type = FileErrorType.NOACCESS
else:
self.error_type = FileErrorType.UNKNOWN
self.error_append(str(error))
def load(self, callback):
thread.run_task(