From ee64301c07fe5a8a363d91670f1caddc4a744abd Mon Sep 17 00:00:00 2001 From: Olivier Gayot Date: Sat, 11 Feb 2023 17:43:46 +0100 Subject: Raise an exception when profile not found Signed-off-by: Olivier Gayot --- monitor-menu.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/monitor-menu.py b/monitor-menu.py index f810f9c..413b12d 100755 --- a/monitor-menu.py +++ b/monitor-menu.py @@ -19,6 +19,10 @@ import dialog import docopt +class NoMatchingProfile(ValueError): + pass + + class MonitorMenu(): def __init__(self, config_file='~/.config/monitor-profiles.json'): with open(expanduser(config_file)) as fh: @@ -41,7 +45,10 @@ class MonitorMenu(): if code in (self.d.ESC, self.d.CANCEL): return - profile = self.profiles[int(profile_idx)] + try: + profile = self.profiles[int(profile_idx)] + except IndexError: + raise NoMatchingProfile from None # We build the command line starting from just "xrandr" and adding # arguments. -- cgit v1.2.3