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', '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(YAML) –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, user_input_as_commented_map)
¶
Transform raw Pydantic error into user-friendly validation error with YAML coordinates.
Why
Pydantic errors contain technical jargon and generic locations unsuitable for end users. This converts them to plain English messages with exact YAML line numbers, mapped via error_dictionary.yaml.
Parameters:
-
plain_error(ErrorDetails) –Raw Pydantic validation error.
-
user_input_as_commented_map(CommentedMap) –YAML dict with line/column metadata.
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, rendercv_dictionary_as_commented_map)
¶
Extract all validation errors from Pydantic exception with deduplication.
Why
Single Pydantic ValidationError contains multiple sub-errors. Entry validation errors include nested causes that must be flattened and deduplicated before display. This aggregates all errors into a single list for table rendering.
Parameters:
-
exception(ValidationError) –Pydantic validation exception.
-
rendercv_dictionary_as_commented_map(CommentedMap) –YAML dict with location metadata.
Returns:
-
list[RenderCVValidationError]–Deduplicated list of user-friendly validation errors.