mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Use FileNotFoundError instead of DeviceError when file/folder is not found
This commit is contained in:
parent
77936feb22
commit
9ab99b34c2
@ -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)}')
|
||||
|
@ -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)
|
||||
|
Loading…
x
Reference in New Issue
Block a user