File size: 3,595 Bytes
9c6594c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
from typing import Any, Optional, Type


class OmegaConfBaseException(Exception):
    # would ideally be typed Optional[Node]
    parent_node: Any
    child_node: Any
    key: Any
    full_key: Optional[str]
    value: Any
    msg: Optional[str]
    cause: Optional[Exception]
    object_type: Optional[Type[Any]]
    object_type_str: Optional[str]
    ref_type: Optional[Type[Any]]
    ref_type_str: Optional[str]

    _initialized: bool = False

    def __init__(self, *_args: Any, **_kwargs: Any) -> None:
        self.parent_node = None
        self.child_node = None
        self.key = None
        self.full_key = None
        self.value = None
        self.msg = None
        self.object_type = None
        self.ref_type = None


class MissingMandatoryValue(OmegaConfBaseException):
    """Thrown when a variable flagged with '???' value is accessed to
    indicate that the value was not set"""


class KeyValidationError(OmegaConfBaseException, ValueError):
    """
    Thrown when an a key of invalid type is used
    """


class ValidationError(OmegaConfBaseException, ValueError):
    """
    Thrown when a value fails validation
    """


class UnsupportedValueType(ValidationError, ValueError):
    """
    Thrown when an input value is not of supported type
    """


class ReadonlyConfigError(OmegaConfBaseException):
    """
    Thrown when someone tries to modify a frozen config
    """


class InterpolationResolutionError(OmegaConfBaseException, ValueError):
    """
    Base class for exceptions raised when resolving an interpolation.
    """


class UnsupportedInterpolationType(InterpolationResolutionError):
    """
    Thrown when an attempt to use an unregistered interpolation is made
    """


class InterpolationKeyError(InterpolationResolutionError):
    """
    Thrown when a node does not exist when resolving an interpolation.
    """


class InterpolationToMissingValueError(InterpolationResolutionError):
    """
    Thrown when a node interpolation points to a node that is set to ???.
    """


class InterpolationValidationError(InterpolationResolutionError, ValidationError):
    """
    Thrown when the result of an interpolation fails the validation step.
    """


class ConfigKeyError(OmegaConfBaseException, KeyError):
    """
    Thrown from DictConfig when a regular dict access would have caused a KeyError.
    """

    msg: str

    def __init__(self, msg: str) -> None:
        super().__init__(msg)
        self.msg = msg

    def __str__(self) -> str:
        """
        Workaround to nasty KeyError quirk: https://bugs.python.org/issue2651
        """
        return self.msg


class ConfigAttributeError(OmegaConfBaseException, AttributeError):
    """
    Thrown from a config object when a regular access would have caused an AttributeError.
    """


class ConfigTypeError(OmegaConfBaseException, TypeError):
    """
    Thrown from a config object when a regular access would have caused a TypeError.
    """


class ConfigIndexError(OmegaConfBaseException, IndexError):
    """
    Thrown from a config object when a regular access would have caused an IndexError.
    """


class ConfigValueError(OmegaConfBaseException, ValueError):
    """
    Thrown from a config object when a regular access would have caused a ValueError.
    """


class ConfigCycleDetectedException(OmegaConfBaseException):
    """
    Thrown when a cycle is detected in the graph made by config nodes.
    """


class GrammarParseError(OmegaConfBaseException):
    """
    Thrown when failing to parse an expression according to the ANTLR grammar.
    """