From 34cda2e1e3a15eb7c2748d2afbd904070a17eccf Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Tue, 20 Feb 2024 09:52:54 +0100 Subject: [PATCH] check-snapshots: make exception for snapshot cache more targeted The code in `check-snapshots` will print "No snapshots cache found at ..." regardless of the error that happens when trying to open the file. This can be misleading if e.g. the issue is permissions to open the file or the file is corrupted. So make the exception more targeted and only catch FileNotFound error and let python how the full error for the other cases. Obviously this can be done in many ways so I'm happy to tweak and e.g. keep catching all exception but print the value etc. --- tools/check-snapshots | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tools/check-snapshots b/tools/check-snapshots index 4c028d4e..95dde726 100755 --- a/tools/check-snapshots +++ b/tools/check-snapshots @@ -23,7 +23,7 @@ def fetch_snapshots_api(url, timeout=SNAPSHOTS_TIMEOUT): start = time.time() try: r = requests.get(url, timeout=timeout) - except BaseException: # pylint: disable=broad-exception-caught + except BaseException as e: # pylint: disable=broad-exception-caught return None elapsed = time.time() - start if r.status_code != 200: @@ -168,7 +168,7 @@ def main(): try: with open(args.cache, encoding="utf8") as f: snapshots = json.load(f) - except BaseException: # pylint: disable=broad-exception-caught + except FileNotFoundError: print(f"No snapshots cache found at {args.cache}") sys.exit(1) else: