errors.py 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. from typing import Any, Optional, Type
  2. class OmegaConfBaseException(Exception):
  3. # would ideally be typed Optional[Node]
  4. parent_node: Any
  5. child_node: Any
  6. key: Any
  7. full_key: Optional[str]
  8. value: Any
  9. msg: Optional[str]
  10. cause: Optional[Exception]
  11. object_type: Optional[Type[Any]]
  12. object_type_str: Optional[str]
  13. ref_type: Optional[Type[Any]]
  14. ref_type_str: Optional[str]
  15. _initialized: bool = False
  16. def __init__(self, *_args: Any, **_kwargs: Any) -> None:
  17. self.parent_node = None
  18. self.child_node = None
  19. self.key = None
  20. self.full_key = None
  21. self.value = None
  22. self.msg = None
  23. self.object_type = None
  24. self.ref_type = None
  25. class MissingMandatoryValue(OmegaConfBaseException):
  26. """Thrown when a variable flagged with '???' value is accessed to
  27. indicate that the value was not set"""
  28. class KeyValidationError(OmegaConfBaseException, ValueError):
  29. """
  30. Thrown when an a key of invalid type is used
  31. """
  32. class ValidationError(OmegaConfBaseException, ValueError):
  33. """
  34. Thrown when a value fails validation
  35. """
  36. class UnsupportedValueType(ValidationError, ValueError):
  37. """
  38. Thrown when an input value is not of supported type
  39. """
  40. class ReadonlyConfigError(OmegaConfBaseException):
  41. """
  42. Thrown when someone tries to modify a frozen config
  43. """
  44. class InterpolationResolutionError(OmegaConfBaseException, ValueError):
  45. """
  46. Base class for exceptions raised when resolving an interpolation.
  47. """
  48. class UnsupportedInterpolationType(InterpolationResolutionError):
  49. """
  50. Thrown when an attempt to use an unregistered interpolation is made
  51. """
  52. class InterpolationKeyError(InterpolationResolutionError):
  53. """
  54. Thrown when a node does not exist when resolving an interpolation.
  55. """
  56. class InterpolationToMissingValueError(InterpolationResolutionError):
  57. """
  58. Thrown when a node interpolation points to a node that is set to ???.
  59. """
  60. class InterpolationValidationError(InterpolationResolutionError, ValidationError):
  61. """
  62. Thrown when the result of an interpolation fails the validation step.
  63. """
  64. class ConfigKeyError(OmegaConfBaseException, KeyError):
  65. """
  66. Thrown from DictConfig when a regular dict access would have caused a KeyError.
  67. """
  68. msg: str
  69. def __init__(self, msg: str) -> None:
  70. super().__init__(msg)
  71. self.msg = msg
  72. def __str__(self) -> str:
  73. """
  74. Workaround to nasty KeyError quirk: https://bugs.python.org/issue2651
  75. """
  76. return self.msg
  77. class ConfigAttributeError(OmegaConfBaseException, AttributeError):
  78. """
  79. Thrown from a config object when a regular access would have caused an AttributeError.
  80. """
  81. class ConfigTypeError(OmegaConfBaseException, TypeError):
  82. """
  83. Thrown from a config object when a regular access would have caused a TypeError.
  84. """
  85. class ConfigIndexError(OmegaConfBaseException, IndexError):
  86. """
  87. Thrown from a config object when a regular access would have caused an IndexError.
  88. """
  89. class ConfigValueError(OmegaConfBaseException, ValueError):
  90. """
  91. Thrown from a config object when a regular access would have caused a ValueError.
  92. """
  93. class ConfigCycleDetectedException(OmegaConfBaseException):
  94. """
  95. Thrown when a cycle is detected in the graph made by config nodes.
  96. """
  97. class GrammarParseError(OmegaConfBaseException):
  98. """
  99. Thrown when failing to parse an expression according to the ANTLR grammar.
  100. """