From d349171f22c8f9d6443144f4ccd9dbffff142259 Mon Sep 17 00:00:00 2001 From: Sina Atalay Date: Sun, 5 May 2024 17:13:02 +0300 Subject: [PATCH] cli: refactor --- rendercv/cli.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/rendercv/cli.py b/rendercv/cli.py index a13a64a..f3cc471 100644 --- a/rendercv/cli.py +++ b/rendercv/cli.py @@ -157,7 +157,7 @@ def handle_validation_error(exception: pydantic.ValidationError): "Field required": "This field is required!", "value is not a valid phone number": "This is not a valid phone number!", "month must be in 1..12": "The month must be between 1 and 12!", - "Value error, day is out of range for month": ( + "day is out of range for month": ( "The day is out of range for the month!" ), "Extra inputs are not permitted": ( @@ -169,6 +169,11 @@ def handle_validation_error(exception: pydantic.ValidationError): ), } + unwanted_texts = [ + "value is not a valid email address: ", + "Value error, " + ] + # Check if this is a section error. If it is, we need to handle it differently. # This is needed because how dm.validate_section_input function raises an exception. # This is done to tell the user which which EntryType RenderCV excepts to see. @@ -226,14 +231,15 @@ def handle_validation_error(exception: pydantic.ValidationError): location = f"{location}.{custom_location}" input = custom_input_value + # Don't show unwanted texts in the error message: + for unwanted_text in unwanted_texts: + message = message.replace(unwanted_text, "") + # Convert the error message to a more user-friendly message if it's in the # error_dictionary: if message in error_dictionary: message = error_dictionary[message] - # Don't show "Value error, ", since the message is already clear. - message = message.replace("Value error, ", "") - # Special case for end_date because Pydantic returns multiple end_date errors # since it has multiple valid formats: if "end_date." in location: