From e4cee86482eac357b25e67a1a6e1288b213b2d47 Mon Sep 17 00:00:00 2001 From: Jan Lindemann Date: Sun, 27 Jul 2025 18:58:28 +0200 Subject: [PATCH] Config.branch(): Add throw argument In case a branch doesn't exist, branch() throws an error. Allow to return None instead. Signed-off-by: Jan Lindemann --- tools/python/jwutils/Config.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/tools/python/jwutils/Config.py b/tools/python/jwutils/Config.py index 24788dc..f2ac485 100644 --- a/tools/python/jwutils/Config.py +++ b/tools/python/jwutils/Config.py @@ -141,13 +141,16 @@ class Config(): # export def value(self, key: str, default = None) -> Optional[str]: return self.get(key, default) - def branch(self, path: str): # type: ignore # Optional[Config]: FIXME: Don't know how to get hold of this type here + def branch(self, path: str, throw: bool=True): # type: ignore # Optional[Config]: FIXME: Don't know how to get hold of this type here if self.__conf: tree = self.__conf.get(path) if tree is None: msg = f'Tried to get non-existent branch "{path}" from config' + if not throw: + slog(DEBUG, msg) + return None self.dump(ERR, msg) - throw(msg) + raise Exception(msg) return Config(tree=tree, parent=self) # type: ignore return None