From 0806d8e177bc8bd34f80416b3692600a6fa8461f Mon Sep 17 00:00:00 2001 From: The Mavik <179817126+themavik@users.noreply.github.com> Date: Wed, 11 Feb 2026 00:17:50 +0530 Subject: [PATCH] fix: remove return from finally block to prevent exception swallowing The `get_log_path` function had a `return` statement inside a `finally` block, which silently swallows any in-flight exceptions including `BaseException` subclasses like `KeyboardInterrupt`. Replace the `try/finally` with a proper `try/except` that catches the expected `ValueError` (from `list.index()`) and `IndexError` (from accessing the next argument), then move the directory creation and return statement outside the exception handler. Fixes #1731 --- elementary/cli/cli.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/elementary/cli/cli.py b/elementary/cli/cli.py index 0bbf24aa9..1a1329487 100644 --- a/elementary/cli/cli.py +++ b/elementary/cli/cli.py @@ -24,9 +24,10 @@ def get_log_path(ctx): ctx_args = ctx.args target_path_flag = "--target-path" target_path = ctx_args[ctx_args.index(target_path_flag) + 1] - finally: - os.makedirs(os.path.abspath(target_path), exist_ok=True) - return os.path.join(target_path, "edr.log") + except (ValueError, IndexError): + pass + os.makedirs(os.path.abspath(target_path), exist_ok=True) + return os.path.join(target_path, "edr.log") def get_quiet_logs(ctx):