Skip to content

Commit 9d20676

Browse files
themavikharitamar
andauthored
fix: remove return from finally block to prevent exception swallowing (#2109)
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 Co-authored-by: Itamar Hartstein <haritamar@gmail.com>
1 parent b5e41fe commit 9d20676

1 file changed

Lines changed: 4 additions & 3 deletions

File tree

elementary/cli/cli.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,10 @@ def get_log_path(ctx):
2424
ctx_args = ctx.args
2525
target_path_flag = "--target-path"
2626
target_path = ctx_args[ctx_args.index(target_path_flag) + 1]
27-
finally:
28-
os.makedirs(os.path.abspath(target_path), exist_ok=True)
29-
return os.path.join(target_path, "edr.log")
27+
except (ValueError, IndexError):
28+
pass
29+
os.makedirs(os.path.abspath(target_path), exist_ok=True)
30+
return os.path.join(target_path, "edr.log")
3031

3132

3233
def get_quiet_logs(ctx):

0 commit comments

Comments
 (0)