From ac6cf0fac7646583f813273b02ccd9056b51269e Mon Sep 17 00:00:00 2001 From: Eric Callahan Date: Mon, 4 Apr 2022 20:31:23 -0400 Subject: [PATCH] Revert "confighelper: match core components to their configuration" This reverts commit d61540cad53c0ef1d018d5a9c73dff4ecbb2e8b8. --- moonraker/confighelper.py | 12 ++++++------ moonraker/moonraker.py | 3 ++- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/moonraker/confighelper.py b/moonraker/confighelper.py index 6b66a79..5531f20 100644 --- a/moonraker/confighelper.py +++ b/moonraker/confighelper.py @@ -79,14 +79,10 @@ class ConfigHelper: return self.section def get_options(self) -> Dict[str, str]: - if not self.config.has_section(self.section): - return {} return dict(self.config[self.section]) def get_hash(self) -> hashlib._Hash: hash = hashlib.sha256() - if not self.config.has_section(self.section): - return hash for option, val in self.config[self.section].items(): hash.update(option.encode()) hash.update(val.encode()) @@ -96,6 +92,8 @@ class ConfigHelper: return [s for s in self.sections() if s.startswith(prefix)] def getsection(self, section: str) -> ConfigHelper: + if section not in self.config: + raise ConfigError(f"No section [{section}] in config") return ConfigHelper(self.server, self.config, section, self.orig_sections, self.parsed) @@ -111,9 +109,11 @@ class ConfigHelper: ) -> _T: try: val = func(self.section, option) - except (configparser.NoOptionError, configparser.NoSectionError) as e: + except configparser.NoOptionError: if isinstance(default, SentinelClass): - raise ConfigError(str(e)) from None + raise ConfigError( + f"No option found ({option}) in section [{self.section}]" + ) from None val = default except Exception: raise ConfigError( diff --git a/moonraker/moonraker.py b/moonraker/moonraker.py index d9a2e9f..a705fe3 100755 --- a/moonraker/moonraker.py +++ b/moonraker/moonraker.py @@ -228,7 +228,8 @@ class Server: return self.components[component_name] try: module = importlib.import_module("components." + component_name) - config = config[component_name] + if component_name in config: + config = config[component_name] load_func = getattr(module, "load_component") component = load_func(config) except Exception: