1
0
Fork 0
mirror of synced 2024-06-01 18:09:47 +12:00

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:
Serene-Arc 2021-04-13 13:22:13 +10:00 committed by Ali Parlakci
parent e672e28a12
commit ab7a0f6a51

View file

@ -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