From e8999363edb9dbc864441686d643ca62581897fa Mon Sep 17 00:00:00 2001 From: Eric Callahan Date: Fri, 26 Aug 2022 05:47:32 -0400 Subject: [PATCH] confighelper: raise duplicate exceptions Moonraker requires that the configuration be parsed in 'strict' mode, ie: duplicate sections are not allowed within the same file and duplicate options are not allowed within the same section. Signed-off-by: Eric Callahan --- moonraker/confighelper.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/moonraker/confighelper.py b/moonraker/confighelper.py index bc1a80c..dc97cc9 100644 --- a/moonraker/confighelper.py +++ b/moonraker/confighelper.py @@ -986,7 +986,10 @@ class FileSourceWrapper(ConfigSourceWrapper): if section not in self.file_section_map: self.file_section_map[section] = [] elif file_index in self.file_section_map[section]: - self.file_section_map[section].remove(file_index) + raise ConfigError( + f"Duplicate section [{section}] in file " + f"{file_path}" + ) self.file_section_map[section].insert(0, file_index) else: # This line must specify an option @@ -996,7 +999,10 @@ class FileSourceWrapper(ConfigSourceWrapper): if key not in self.file_option_map: self.file_option_map[key] = [] elif file_index in self.file_option_map[key]: - self.file_option_map[key].remove(file_index) + raise ConfigError( + f"Duplicate option '{option}' in section " + f"[{last_section}], file {file_path} " + ) self.file_option_map[key].insert(0, file_index) buffer.append(line) self._write_buffer(buffer, file_path)