pydantic_error_handling
¶
error_dictionary = cast(dict[str, str], read_yaml(pathlib.Path(__file__).parent / 'error_dictionary.yaml'))
module-attribute
¶
unwanted_locations = ('tagged-union', 'list', 'literal', 'int', 'str', 'constrained-str', 'function-after')
module-attribute
¶
unwanted_texts = ('value is not a valid email address: ', 'Value error, ')
module-attribute
¶
get_coordinates_of_a_key_in_a_yaml_object(yaml_object, location)
¶
Resolve dotted location path to exact YAML source coordinates.
Why
Error tables must show users exactly which line/column contains the invalid value. Recursive traversal through CommentedMap's lc.data preserves coordinates at every nesting level.
Example
Parameters:
-
yaml_object(CommentedMap) –Root YAML object with location metadata.
-
location(tuple[str, ...]) –Path segments from root to target key.
Returns:
-
tuple[tuple[int, int], tuple[int, int]]–((start_line, start_col), (end_line, end_col)) in 1-indexed coordinates.
Source code in src/rendercv/schema/pydantic_error_handling.py
get_inner_yaml_object_from_its_key(yaml_object, location_key)
¶
Navigate one level into YAML structure and extract coordinates.
Why
Error locations are dotted paths like cv.sections.education.0.degree.
Each traversal step must extract both the nested object and its exact
source coordinates for error highlighting.
Parameters:
-
yaml_object(CommentedMap) –Current YAML object being traversed.
-
location_key(str) –Single key or list index as string.
Returns:
-
tuple[CommentedMap, tuple[tuple[int, int], tuple[int, int]]]–Tuple of nested object and ((start_line, start_col), (end_line, end_col)).
Source code in src/rendercv/schema/pydantic_error_handling.py
parse_plain_pydantic_error(plain_error, input_dictionary, overlay_sources=None)
¶
Transform raw Pydantic error into user-friendly validation error with YAML coordinates.
Parameters:
-
plain_error(ErrorDetails) –Raw Pydantic validation error.
-
input_dictionary(CommentedMap | dict[str, Any]) –YAML dict with line/column metadata.
-
overlay_sources(dict[str, CommentedMap] | None, default:None) –Per-section CommentedMaps from overlays (for correct coordinates).
Returns:
-
RenderCVValidationError–Structured error with location tuple, friendly message, and YAML coordinates.
Source code in src/rendercv/schema/pydantic_error_handling.py
parse_validation_errors(exception, input_dictionary, overlay_sources=None)
¶
Extract all validation errors from Pydantic exception with deduplication.
Parameters:
-
exception(ValidationError) –Pydantic validation exception.
-
input_dictionary(CommentedMap | dict[str, Any]) –YAML dict with location metadata.
-
overlay_sources(dict[str, CommentedMap] | None, default:None) –Per-section CommentedMaps from overlays (for correct coordinates).
Returns:
-
list[RenderCVValidationError]–Deduplicated list of user-friendly validation errors.