From c91dc126cd5733fa2b4098e8431ef976b941ba7b Mon Sep 17 00:00:00 2001 From: Dominick Leppich Date: Mon, 25 Nov 2024 09:58:15 +0100 Subject: [PATCH] fix: better logging for unsuccessful mets file processing --- migration/lib/mets_manipulator.py | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/migration/lib/mets_manipulator.py b/migration/lib/mets_manipulator.py index 92f42f3..e05349e 100644 --- a/migration/lib/mets_manipulator.py +++ b/migration/lib/mets_manipulator.py @@ -37,14 +37,18 @@ def process_mets_file(self): logging.error(error) self.ctx.log_issue(self.file_path, error) return - - root = tree.getroot() - self.process_node(root) + try: + root = tree.getroot() + self.process_node(root) - if self.changed and not self.ctx.dry: - self.create_backup() - tree.write(self.file_path, encoding='utf-8', xml_declaration=True) - self.ctx.log_processed(self.file_path) + if self.changed and not self.ctx.dry: + self.create_backup() + tree.write(self.file_path, encoding='utf-8', xml_declaration=True) + self.ctx.log_processed(self.file_path) + except Exception as e: + error = f'Something very unexpected happened during processing of mets file {self.file_path}: {e}' + logging.critical(error) + raise Exception(error) def process_node(self, node): if self.is_manual_id_reference(node):