diff --git a/src/calibre/devices/mtp/unix/driver.py b/src/calibre/devices/mtp/unix/driver.py index 2a2b31bd33..d3d8047e51 100644 --- a/src/calibre/devices/mtp/unix/driver.py +++ b/src/calibre/devices/mtp/unix/driver.py @@ -436,7 +436,7 @@ class MTP_DEVICE(MTPDeviceBase): parent_id = self.libmtp.LIBMTP_FILES_AND_FOLDERS_ROOT if parent.is_storage else parent.object_id x = self.dev.list_folder_by_name(parent.storage_id, parent_id, names) if x is None: - raise DeviceError(f'Could not find folder named: {"/".join(names)} in {parent.full_path}') + raise FileNotFoundError(f'Could not find folder named: {"/".join(names)} in {parent.full_path}') return x @synchronous @@ -462,7 +462,7 @@ class MTP_DEVICE(MTPDeviceBase): parent_id = self.libmtp.LIBMTP_FILES_AND_FOLDERS_ROOT if parent.is_storage else parent.object_id x = self.dev.get_file_by_name(parent.storage_id, parent_id, names, stream, callback) if x is None: - raise DeviceError(f'Could not find file named: {"/".join(names)} in {parent.full_path}') + raise FileNotFoundError(f'Could not find file named: {"/".join(names)} in {parent.full_path}') ok, errs = x if not ok: raise DeviceError(f'Failed to get file: {"/".join(names)} in {parent.full_path} with errors: {self.format_errorstack(errs)}') diff --git a/src/calibre/devices/mtp/windows/driver.py b/src/calibre/devices/mtp/windows/driver.py index 57b408fa14..6f8efb3425 100644 --- a/src/calibre/devices/mtp/windows/driver.py +++ b/src/calibre/devices/mtp/windows/driver.py @@ -398,7 +398,7 @@ class MTP_DEVICE(MTPDeviceBase): raise ValueError(f'{parent.full_path} is not a folder') x = self.dev.list_folder_by_name(parent.object_id, names) if x is None: - raise DeviceError(f'Could not find folder named: {"/".join(names)} in {parent.full_path}') + raise FileNotFoundError(f'Could not find folder named: {"/".join(names)} in {parent.full_path}') return list(x.values()) @same_thread @@ -423,8 +423,10 @@ class MTP_DEVICE(MTPDeviceBase): except self.wpd.WPDFileBusy: time.sleep(2) self.dev.get_file_by_name(parent.object_id, names, stream, callback) + except KeyError as e: + raise FileNotFoundError(f'Failed to find the file {os.sep.join(names)} in {parent.full_path}') from e except Exception as e: - raise DeviceError(f'Failed to fetch the file {os.sep.join(names)} from {parent.full_path} with error: {as_unicode(e)}') + raise DeviceError(f'Failed to fetch the file {os.sep.join(names)} in {parent.full_path} with error: {as_unicode(e)}') stream.seek(0) if set_name: stream.name = '/'.join(names)