From 460a7c17cfd2899e745ef672aabf05afe470a933 Mon Sep 17 00:00:00 2001 From: pedro Date: Thu, 26 Sep 2024 11:24:38 -0300 Subject: [PATCH] pxe: add try-exception for writing fallback path --- workbench-script.py | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/workbench-script.py b/workbench-script.py index e4001a5..be482be 100644 --- a/workbench-script.py +++ b/workbench-script.py @@ -266,14 +266,17 @@ def save_snapshot_in_disk(snapshot, path): f.write(json.dumps(snapshot)) print(f"workbench: INFO: Snapshot written in path '{filename}'") except Exception as e: - print(f"workbench: WARNING: Failed to write in snapshots directory: {e}. Attempting to save in actual path.") - fallback_filename = "{}/{}_{}.json".format( - path, - datetime.now().strftime("%Y%m%d-%H_%M_%S"), - snapshot['uuid']) + try: + print(f"workbench: WARNING: Failed to write in snapshots directory: {e}. Attempting to save in actual path.") + fallback_filename = "{}/{}_{}.json".format( + path, + datetime.now().strftime("%Y%m%d-%H_%M_%S"), + snapshot['uuid']) with open(fallback_filename, "w") as f: f.write(json.dumps(snapshot)) - print(f"workbench: INFO: Snapshot written in fallback path '{fallback_filename}'") + print(f"workbench: INFO: Snapshot written in fallback path '{fallback_filename}'") + except Exception as e: + print(f"workbench: ERROR: Failed to write in fallback path: {fallback_error}. Could not save snapshot locally.") # TODO sanitize url, if url is like this, it fails # url = 'http://127.0.0.1:8000/api/snapshot/'