Page MenuHomeVyOS Platform

Replace bare `except:` clauses with specific exception types in Python code
Open, LowPublic

Description

Bare except: clauses catch all exceptions including KeyboardInterrupt and SystemExit, which can mask critical errors and prevent proper program termination. Replace each with the narrowest exception type that the surrounding code actually needs to handle.

Files and exception types

FileLineReplacementRationale
src/conf_mode/interfaces_ethernet.py162ExceptionInterface MTU lookup may fail for various OS-level reasons
src/conf_mode/vpp_interfaces_bonding.py181ValueErrorassert_mac() raises ValueError on invalid MAC
src/conf_mode/container.py180IndexErrorList comprehension [0] on empty filtered list
src/conf_mode/container.py186IndexErrorList comprehension [0] on empty filtered list
python/vyos/config.py124ExceptionACME cert loading can fail from file I/O, parsing, etc.
python/vyos/configverify.py49ExceptionInterface min/max MTU sysfs reads may fail
python/vyos/configverify.py436(TypeError, ValueError)str() conversion of DH keysize parameter

GitHub PR

https://github.com/vyos/vyos-1x/pull/5074

Details

Version
rolling
Issue type
Bug (incorrect behavior)