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
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 | |
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.