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 <arksine.code@gmail.com>
This commit is contained in:
Eric Callahan 2022-08-26 05:47:32 -04:00
parent 78605db001
commit e8999363ed
No known key found for this signature in database
GPG Key ID: 5A1EB336DFB4C71B
1 changed files with 8 additions and 2 deletions

View File

@ -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)