sift_py.ingestion.config.yaml.error

 1from typing import Any, List, Optional
 2
 3from typing_extensions import Self
 4
 5_PREFIX = "  "
 6_YAML_SEP = "---"
 7_LIST_ITEM_PREFIX = "- "
 8
 9
10class YamlConfigError(Exception):
11    """
12    When the YAML config has missing or invalid properties.
13    """
14
15    message: str
16
17    def __init__(self, message: str):
18        super().__init__(message)
19
20    @classmethod
21    def _invalid_property(
22        cls,
23        actual_value: Any,
24        key_name: str,
25        expected_type: str,
26        ancestors: Optional[List[str]] = None,
27    ) -> Self:
28        header = f"Expected '{key_name.lstrip(_LIST_ITEM_PREFIX)}' to be <{expected_type}> but it is <{type(actual_value).__name__}>\n{_YAML_SEP}\n"
29
30        if ancestors is None or len(ancestors) == 0:
31            return cls(f"{header}{key_name}: <{expected_type}>")
32
33        key_value_path = ""
34
35        current_indentation_level = 0
36
37        for ancestor in ancestors:
38            key_value_path += f"{_PREFIX * current_indentation_level}{ancestor}:\n"
39            current_indentation_level += 1
40
41        key_value_path += f"{_PREFIX * current_indentation_level}{key_name}: <{expected_type}>"
42        output = f"{header}{key_value_path}"
43
44        return cls(output)
class YamlConfigError(builtins.Exception):
11class YamlConfigError(Exception):
12    """
13    When the YAML config has missing or invalid properties.
14    """
15
16    message: str
17
18    def __init__(self, message: str):
19        super().__init__(message)
20
21    @classmethod
22    def _invalid_property(
23        cls,
24        actual_value: Any,
25        key_name: str,
26        expected_type: str,
27        ancestors: Optional[List[str]] = None,
28    ) -> Self:
29        header = f"Expected '{key_name.lstrip(_LIST_ITEM_PREFIX)}' to be <{expected_type}> but it is <{type(actual_value).__name__}>\n{_YAML_SEP}\n"
30
31        if ancestors is None or len(ancestors) == 0:
32            return cls(f"{header}{key_name}: <{expected_type}>")
33
34        key_value_path = ""
35
36        current_indentation_level = 0
37
38        for ancestor in ancestors:
39            key_value_path += f"{_PREFIX * current_indentation_level}{ancestor}:\n"
40            current_indentation_level += 1
41
42        key_value_path += f"{_PREFIX * current_indentation_level}{key_name}: <{expected_type}>"
43        output = f"{header}{key_value_path}"
44
45        return cls(output)

When the YAML config has missing or invalid properties.

YamlConfigError(message: str)
18    def __init__(self, message: str):
19        super().__init__(message)
message: str
Inherited Members
builtins.BaseException
with_traceback
args