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]]: ) -> list[tuple[Path, Resource]]:
out = [] out = []
if len(resources) == 1: 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: else:
for i, res in enumerate(resources, start=1): for i, res in enumerate(resources, start=1):
logger.log(9, f'Formatting filename with index {i}') 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 return out
@staticmethod @staticmethod