From 8e9e278750ee52a0d7e057c0666555b03880ced0 Mon Sep 17 00:00:00 2001 From: Christian Breunig Date: Thu, 5 Mar 2026 21:09:05 +0000 Subject: vyos.debug: T8347: fix UnboundLocalError in try/finally statement Pylint warns about mask being used before assignment because mask is created inside the try block. While os.umask() itself is highly unlikely to fail, Python can raise asynchronous exceptions like KeyboardInterrupt or MemoryError at any given moment. If one of those exceptions occurs precisely after the try: statement but before "mask = os.umask(0o111)" completes, Python calls finally with "os.umask(mask)" causing UnboundLocalError. --- python/vyos/debug.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'python') diff --git a/python/vyos/debug.py b/python/vyos/debug.py index 5b6e8172e..1a6924ef5 100644 --- a/python/vyos/debug.py +++ b/python/vyos/debug.py @@ -38,13 +38,12 @@ def message(message, flag='', destination=sys.stdout): if not logfile: return enable + mask = os.umask(0o111) try: # at boot the file is created as root:vyattacfg # at runtime the file is created as user:vyattacfg # but the helper scripts are not run as this so it # need the default permission to be 666 (an not 660) - mask = os.umask(0o111) - with open(logfile, 'a') as f: f.write(_timed(_format('log', message))) finally: -- cgit v1.2.3