Coverage for sygaldry / errors.py: 95%

34 statements  

« prev     ^ index     » next       coverage.py v7.13.5, created at 2026-03-31 23:33 -0400

1from __future__ import annotations 

2 

3__author__ = "Rohan B. Dalton" 

4 

5from typing import Optional 

6 

7 

8class SygaldryError(Exception): 

9 """ 

10 Base error for all Sygaldry failures. 

11 

12 :param message: Human-readable error message. 

13 :param file_path: Source config file path, if known. 

14 :param config_path: Dotted config path for context. 

15 :type message: str 

16 :type file_path: str | None 

17 :type config_path: str | None 

18 """ 

19 

20 def __init__( 

21 self, 

22 message: str, 

23 file_path: str | None = None, 

24 config_path: str | None = None, 

25 ): 

26 super().__init__(message) 

27 self._message = message 

28 self._file_path = file_path 

29 self._config_path = config_path 

30 

31 def __str__(self) -> str: 

32 """ 

33 Render the error with optional file/config context. 

34 

35 :returns: Formatted error string with file and config path context. 

36 :rtype: str 

37 """ 

38 parts = list() 

39 if self._file_path: 

40 parts.append(f"file='{self._file_path}'") 

41 if self._config_path: 

42 parts.append(f"path='{self._config_path}'") 

43 if parts: 

44 return f"{self._message} ({', '.join(parts)})" 

45 return self._message 

46 

47 

48class LoadError(SygaldryError): 

49 """ 

50 Errors during file loading or parsing. 

51 """ 

52 

53 

54class ParseError(LoadError): 

55 """ 

56 Parsing failures for YAML or TOML. 

57 """ 

58 

59 

60class IncludeError(LoadError): 

61 """ 

62 Errors during include resolution or deep merge. 

63 """ 

64 

65 

66class CircularIncludeError(IncludeError): 

67 """ 

68 Circular include detected. 

69 """ 

70 

71 

72class ValidationError(SygaldryError): 

73 """ 

74 Schema or config validation failures. 

75 """ 

76 

77 

78class ConfigReferenceError(ValidationError): 

79 """ 

80 Missing or invalid _ref targets. 

81 """ 

82 

83 

84class CircularReferenceError(ConfigReferenceError): 

85 """ 

86 Circular _ref detected. 

87 """ 

88 

89 

90class InterpolationError(ValidationError): 

91 """ 

92 Interpolation failures. 

93 """ 

94 

95 

96class CircularInterpolationError(InterpolationError): 

97 """ 

98 Circular interpolation detected. 

99 """ 

100 

101 

102class ImportResolutionError(SygaldryError): 

103 """ 

104 Import or dotted path resolution failures. 

105 """ 

106 

107 

108class ResolutionError(SygaldryError): 

109 """ 

110 Errors during recursive resolution. 

111 """ 

112 

113 

114class ConstructorError(ResolutionError): 

115 """ 

116 Constructor invocation failures. 

117 """ 

118 

119 

120class ConfigConflictError(SygaldryError): 

121 """ 

122 Cache conflicts for identical keys with differing specs. 

123 """ 

124 

125 

126class CLIError(SygaldryError): 

127 """ 

128 Errors originating from CLI argument processing. 

129 """ 

130 

131 

132if __name__ == "__main__": 132 ↛ 133line 132 didn't jump to line 133 because the condition on line 132 was never true

133 pass