Catch errors when resources have no extension
This is related to #266 and will prevent the BDFR from completely crashing when a file extension is unknown
This commit is contained in:
parent
e672e28a12
commit
ab7a0f6a51
|
@ -132,11 +132,19 @@ class FileNameFormatter:
|
|||
) -> list[tuple[Path, Resource]]:
|
||||
out = []
|
||||
if len(resources) == 1:
|
||||
out.append((self.format_path(resources[0], destination_directory, None), resources[0]))
|
||||
try:
|
||||
out.append((self.format_path(resources[0], destination_directory, None), resources[0]))
|
||||
except BulkDownloaderException as e:
|
||||
logger.error(f'Could not generate file path for resource {resources[0].url}: {e}')
|
||||
logger.exception('Could not generate file path')
|
||||
else:
|
||||
for i, res in enumerate(resources, start=1):
|
||||
logger.log(9, f'Formatting filename with index {i}')
|
||||
out.append((self.format_path(res, destination_directory, i), res))
|
||||
try:
|
||||
out.append((self.format_path(res, destination_directory, i), res))
|
||||
except BulkDownloaderException as e:
|
||||
logger.error(f'Could not generate file path for resource {res.url}: {e}')
|
||||
logger.exception('Could not generate file path')
|
||||
return out
|
||||
|
||||
@staticmethod
|
||||
|
|
Loading…
Reference in a new issue