Config: Make branch() throw exception on inexistent path

Config.branch(path) just silently returns the entire tree if path
doesn't exist in the config. Fix that.

Signed-off-by: Jan Lindemann <jan@janware.com>
This commit is contained in:
Jan Lindemann 2025-02-15 08:19:25 +01:00
commit 79a3696eaa

View file

@ -113,7 +113,12 @@ class Config(): # export
def branch(self, path: str): # type: ignore # Optional[Config]: FIXME: Don't know how to get hold of this type here
if self.__conf:
return Config(tree=self.__conf.get(path), parent=self) # type: ignore
tree = self.__conf.get(path)
if tree is None:
msg = f'Tried to get non-existent branch "{path}" from config'
self.dump(ERR, msg)
throw(msg)
return Config(tree=tree, parent=self) # type: ignore
return None
def dump(self, prio: int, *args, **kwargs) -> None: