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
« 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
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]]
13OVERLAY_SOURCE_TO_YAML_SOURCE: dict[OverlaySourceKey, YamlSource] = {
14 "design": "design_yaml_file",
15 "locale": "locale_yaml_file",
16 "settings": "settings_yaml_file",
17}
20@dataclass
21class RenderCVValidationError:
22 """Structured validation error with YAML source location for error reporting.
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 """
30 schema_location: tuple[str, ...] | None
31 yaml_location: YamlLocation | None
32 yaml_source: YamlSource
33 message: str
34 input: str
37@dataclass
38class RenderCVUserError(ValueError):
39 """User-facing error for recoverable problems like invalid input or missing files.
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 """
47 message: str | None = field(default=None)
50@dataclass
51class RenderCVUserValidationError(ValueError):
52 """User-facing error carrying multiple structured validation errors.
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 """
60 validation_errors: list[RenderCVValidationError]
63@dataclass
64class RenderCVInternalError(RuntimeError):
65 """Internal error indicating a bug in RenderCV logic.
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 """
73 message: str