diff --git a/src/music_kraken/utils/config/config.py b/src/music_kraken/utils/config/config.py index f35367a..d4254c8 100644 --- a/src/music_kraken/utils/config/config.py +++ b/src/music_kraken/utils/config/config.py @@ -2,6 +2,7 @@ from typing import Union, Tuple, Dict, Iterable, List import logging import os +from ..exception.config import SettingNotFound, SettingValueError from ..path_manager import LOCATIONS from .base_classes import Description, Attribute, Section, EmptyLine, COMMENT_PREFIX from .audio import AUDIO_SECTION @@ -44,10 +45,16 @@ class Config: self._length += 1 def set_name_to_value(self, name: str, value: str): + """ + :raises SettingValueError, SettingNotFound: + :param name: + :param value: + :return: + """ if name not in self._name_section_map: - raise KeyError(f"There is no such setting, as: {name}") + raise SettingNotFound(setting_name=name) - self._name_section_map[name][name] = value + self._name_section_map[name].modify_setting(setting_name=name, new_value=value) def __len__(self): return self._length @@ -57,6 +64,12 @@ class Config: return "\n\n".join(str(element) for element in self.config_elements) def _parse_conf_line(self, line: str, index: int): + """ + :raises SettingValueError, SettingNotFound: + :param line: + :param index: + :return: + """ line = line.strip() if line.startswith(COMMENT_PREFIX): return diff --git a/src/music_kraken/utils/exception/config.py b/src/music_kraken/utils/exception/config.py index 845bec7..7e33c8c 100644 --- a/src/music_kraken/utils/exception/config.py +++ b/src/music_kraken/utils/exception/config.py @@ -6,6 +6,9 @@ class SettingNotFound(SettingException): def __init__(self, setting_name: str): self.setting_name = setting_name + def __str__(self): + return f"Setting '{self.setting_name}' not found." + class SettingValueError(SettingException): def __init__(self, setting_name: str, setting_value: str, rule: str):