From 65788b36afd3243266c8de4d251adf2621478b04 Mon Sep 17 00:00:00 2001 From: pedro Date: Tue, 12 Nov 2024 14:37:55 +0100 Subject: [PATCH] up_snapshots: simplify and clarify errors specially, do not halt in case of errors, just print them in logs --- evidence/management/commands/up_snapshots.py | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/evidence/management/commands/up_snapshots.py b/evidence/management/commands/up_snapshots.py index b1ca8c7..36f5c28 100644 --- a/evidence/management/commands/up_snapshots.py +++ b/evidence/management/commands/up_snapshots.py @@ -54,23 +54,15 @@ class Command(BaseCommand): self.snapshots.append((content, path_name)) - except json.JSONDecodeError as e: - logger.error("JSON decode error in file %s: %s", filepath, e) - raise ValueError(f"Invalid JSON format in file. Check for file integrity.") from e - except FileNotFoundError as e: - logger.error("File not found: %s", filepath) - raise FileNotFoundError(f"File not found") from e - #or we cath'em all except Exception as e: - logger.exception("Unexpected error when opening file %s: %s", filepath, e) - raise Exception(f"Unexpected error when opening file") from e + logger.error("Could not open file %s: %s", filepath, e) def parsing(self): for s, p in self.snapshots: try: self.devices.append(Build(s, self.user)) move_json(p, self.user.institution.name) - except Exception as err: + except Exception as e: snapshot_id = s.get("uuid", "") - txt = "Could not parse snapshot: %s" - logger.error(txt, snapshot_id) + txt = "Could not parse snapshot %s: %s" + logger.error(txt, snapshot_id, e)