Coverage for src / rendercv / exception.py: 100%

22 statements  

« prev     ^ index     » next       coverage.py v7.13.4, created at 2026-03-25 13:49 +0000

1from dataclasses import dataclass, field 

2from typing import Literal 

3 

4type YamlSource = Literal[ 

5 "main_yaml_file", 

6 "design_yaml_file", 

7 "locale_yaml_file", 

8 "settings_yaml_file", 

9] 

10type OverlaySourceKey = Literal["design", "locale", "settings"] 

11type YamlLocation = tuple[tuple[int, int], tuple[int, int]] 

12 

13OVERLAY_SOURCE_TO_YAML_SOURCE: dict[OverlaySourceKey, YamlSource] = { 

14 "design": "design_yaml_file", 

15 "locale": "locale_yaml_file", 

16 "settings": "settings_yaml_file", 

17} 

18 

19 

20@dataclass 

21class RenderCVValidationError: 

22 """Structured validation error with YAML source location for error reporting. 

23 

24 Why: 

25 Pydantic errors lack YAML file position info. This bridges the gap 

26 by pairing schema-level error details with YAML line/column positions 

27 so the CLI can display precise, user-friendly error locations. 

28 """ 

29 

30 schema_location: tuple[str, ...] | None 

31 yaml_location: YamlLocation | None 

32 yaml_source: YamlSource 

33 message: str 

34 input: str 

35 

36 

37@dataclass 

38class RenderCVUserError(ValueError): 

39 """User-facing error for recoverable problems like invalid input or missing files. 

40 

41 Why: 

42 CLI commands catch this to display clean error panels without stack 

43 traces. Separating user errors from internal errors ensures only 

44 actionable messages reach end users. 

45 """ 

46 

47 message: str | None = field(default=None) 

48 

49 

50@dataclass 

51class RenderCVUserValidationError(ValueError): 

52 """User-facing error carrying multiple structured validation errors. 

53 

54 Why: 

55 YAML validation can produce many errors at once. Aggregating them 

56 in a single exception enables the CLI to display all problems in 

57 one pass rather than stopping at the first. 

58 """ 

59 

60 validation_errors: list[RenderCVValidationError] 

61 

62 

63@dataclass 

64class RenderCVInternalError(RuntimeError): 

65 """Internal error indicating a bug in RenderCV logic. 

66 

67 Why: 

68 Distinguishes programmer errors (unreachable states, broken 

69 invariants) from user errors. These should never reach end users 

70 in normal operation and indicate code that needs fixing. 

71 """ 

72 

73 message: str