From 637f51f0be8081c1bca97c1a0969e24ac353a07f Mon Sep 17 00:00:00 2001 From: Florian Date: Thu, 9 Oct 2025 08:07:57 +0200 Subject: [PATCH] Gracefully opening secrets with exit on failure --- src/secret_handler.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/secret_handler.py b/src/secret_handler.py index 724a972..33d66a5 100644 --- a/src/secret_handler.py +++ b/src/secret_handler.py @@ -1,3 +1,12 @@ +import sys + def return_credentials(path: str)->str: - with open (path) as file: - return file.read().strip() \ No newline at end of file + try: + with open (path) as file: + return file.read().strip() + except FileNotFoundError: + print(f"[FATAL] Secret file not found: {path}") + sys.exit(1) + except Exception as e: + print(f"[FATAL] Failed to read secret file {path}: {e}") + sys.exit(1)