From 12975347ee5ece99bc3f0502ea3a161df6075a25 Mon Sep 17 00:00:00 2001 From: Marcus Albertsson Date: Fri, 29 Jun 2018 08:56:25 +0100 Subject: [PATCH] Fix: Exception in conf utils The bug was related to trying to split a string with unstript spaces in the action parameter. It resulted in a unbound error as there was no previous raise when getting the key from args_funcs. The fix is twofold, it makes sure that we raise the keyerror if we're trying to grab a non existing key and we're stripping the spaces from the action before splitting. This should fix both the unbound error and the not being able to resolve correct actions. --- kitty/conf/utils.py | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/kitty/conf/utils.py b/kitty/conf/utils.py index 0bec1ee95..0fdbaf31b 100644 --- a/kitty/conf/utils.py +++ b/kitty/conf/utils.py @@ -228,19 +228,28 @@ def parse_kittens_shortcut(sc): def parse_kittens_func_args(action, args_funcs): - parts = action.split(' ', 1) + parts = action.strip().split(' ', 1) func = parts[0] if len(parts) == 1: return func, () rest = parts[1] - parser = args_funcs.get(func) - if parser is not None: - try: - func, args = parser(func, rest) - except Exception: - raise ValueError('Unknown key action: {}'.format(action)) + + try: + parser = args_funcs[func] + except KeyError: + raise KeyError( + "Couldn't get valid key from {}. Check if input action: " + "{} is valid".format(parts, action) + ) + + try: + func, args = parser(func, rest) + except Exception: + raise ValueError('Unknown key action: {}'.format(action)) + if not isinstance(args, (list, tuple)): args = (args,) + return func, tuple(args)