mirror of https://github.com/eyhc1/rendercv.git
improve validation messages
This commit is contained in:
parent
4258de812a
commit
a21af89f08
|
@ -253,6 +253,9 @@ def generate_json_schema(output_directory: str) -> str:
|
||||||
# Loop through $defs and remove docstring descriptions and fix optional
|
# Loop through $defs and remove docstring descriptions and fix optional
|
||||||
# fields
|
# fields
|
||||||
for key, value in json_schema["$defs"].items():
|
for key, value in json_schema["$defs"].items():
|
||||||
|
# Don't allow additional properties
|
||||||
|
value["additionalProperties"] = False
|
||||||
|
|
||||||
if "This class" in value["description"]:
|
if "This class" in value["description"]:
|
||||||
del value["description"]
|
del value["description"]
|
||||||
|
|
||||||
|
@ -509,15 +512,15 @@ class Design(BaseModel):
|
||||||
if model.theme == "classic":
|
if model.theme == "classic":
|
||||||
model.options = ClassicThemeOptions()
|
model.options = ClassicThemeOptions()
|
||||||
else:
|
else:
|
||||||
raise RuntimeError("Unknown theme!")
|
raise RuntimeError("Unknown theme 👿")
|
||||||
else:
|
else:
|
||||||
if model.theme == "classic":
|
if model.theme == "classic":
|
||||||
if not isinstance(model.options, ClassicThemeOptions):
|
if not isinstance(model.options, ClassicThemeOptions):
|
||||||
raise ValueError(
|
raise ValueError(
|
||||||
"Theme is classic but options is not classic theme options!"
|
"Theme is classic but options is not classic theme options 🥱"
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
raise RuntimeError("Theme is neither classic nor awesome-cv!")
|
raise RuntimeError("Unknown theme 👿")
|
||||||
|
|
||||||
return model
|
return model
|
||||||
|
|
||||||
|
@ -527,7 +530,7 @@ class Design(BaseModel):
|
||||||
# Go to fonts directory and check if the font exists:
|
# Go to fonts directory and check if the font exists:
|
||||||
fonts_directory = str(files("rendercv").joinpath("templates", "fonts"))
|
fonts_directory = str(files("rendercv").joinpath("templates", "fonts"))
|
||||||
if font not in os.listdir(fonts_directory):
|
if font not in os.listdir(fonts_directory):
|
||||||
raise ValueError(f'The font "{font}" is not found in the "fonts" directory')
|
raise ValueError(f'The font "{font}" is not found in the "fonts" directory 🥴')
|
||||||
else:
|
else:
|
||||||
font_directory = os.path.join(fonts_directory, font)
|
font_directory = os.path.join(fonts_directory, font)
|
||||||
required_files = [
|
required_files = [
|
||||||
|
@ -538,7 +541,7 @@ class Design(BaseModel):
|
||||||
]
|
]
|
||||||
for file in required_files:
|
for file in required_files:
|
||||||
if file not in os.listdir(font_directory):
|
if file not in os.listdir(font_directory):
|
||||||
raise ValueError(f"{file} is not found in the {font} directory!")
|
raise ValueError(f"{file} is not found in the {font} directory 😡")
|
||||||
|
|
||||||
return font
|
return font
|
||||||
|
|
||||||
|
@ -549,7 +552,7 @@ class Design(BaseModel):
|
||||||
template_directory = str(files("rendercv").joinpath("templates", theme))
|
template_directory = str(files("rendercv").joinpath("templates", theme))
|
||||||
if f"{theme}.tex.j2" not in os.listdir(template_directory):
|
if f"{theme}.tex.j2" not in os.listdir(template_directory):
|
||||||
raise ValueError(
|
raise ValueError(
|
||||||
f'The theme "{theme}" is not found in the "templates" directory!'
|
f'The theme "{theme}" is not found in the "templates" directory 🤥'
|
||||||
)
|
)
|
||||||
|
|
||||||
return theme
|
return theme
|
||||||
|
@ -685,7 +688,7 @@ class Event(BaseModel):
|
||||||
|
|
||||||
if model.start_date > end_date:
|
if model.start_date > end_date:
|
||||||
raise ValueError(
|
raise ValueError(
|
||||||
'"start_date" is after "end_date". Please check the dates!'
|
'"start_date" can not be after "end_date". Please check the dates 👻'
|
||||||
)
|
)
|
||||||
|
|
||||||
return model
|
return model
|
||||||
|
@ -704,7 +707,7 @@ class Event(BaseModel):
|
||||||
elif isinstance(self.date, Date):
|
elif isinstance(self.date, Date):
|
||||||
date_and_location_strings.append(format_date(self.date))
|
date_and_location_strings.append(format_date(self.date))
|
||||||
else:
|
else:
|
||||||
raise RuntimeError("Date is neither a string nor a Date object!")
|
raise RuntimeError("Date is neither a string nor a Date object 😵")
|
||||||
elif self.start_date is not None and self.end_date is not None:
|
elif self.start_date is not None and self.end_date is not None:
|
||||||
start_date = format_date(self.start_date)
|
start_date = format_date(self.start_date)
|
||||||
|
|
||||||
|
@ -918,7 +921,7 @@ class PublicationEntry(Event):
|
||||||
try:
|
try:
|
||||||
urllib.request.urlopen(doi_url)
|
urllib.request.urlopen(doi_url)
|
||||||
except urllib.request.HTTPError:
|
except urllib.request.HTTPError:
|
||||||
raise ValueError(f"{doi} cannot be found in the DOI System.")
|
raise ValueError(f"{doi} cannot be found in the DOI System 🤖")
|
||||||
|
|
||||||
return doi
|
return doi
|
||||||
|
|
||||||
|
@ -984,7 +987,7 @@ class Connection(BaseModel):
|
||||||
elif self.name == "location":
|
elif self.name == "location":
|
||||||
url = None
|
url = None
|
||||||
else:
|
else:
|
||||||
raise RuntimeError(f'"{self.name}" is not a valid connection!"')
|
raise RuntimeError(f'"{self.name}" is not a valid connection 🤡')
|
||||||
|
|
||||||
return url
|
return url
|
||||||
|
|
||||||
|
@ -1153,7 +1156,7 @@ class CurriculumVitae(BaseModel):
|
||||||
duplicates = {val for val in section_names if (val in seen or seen.add(val))}
|
duplicates = {val for val in section_names if (val in seen or seen.add(val))}
|
||||||
if len(duplicates) > 0:
|
if len(duplicates) > 0:
|
||||||
raise ValueError(
|
raise ValueError(
|
||||||
"The section names should be unique. The following section names are"
|
"The section names should be unique 🧐. The following section names are"
|
||||||
f" duplicated: {duplicates}"
|
f" duplicated: {duplicates}"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -1250,7 +1253,7 @@ class CurriculumVitae(BaseModel):
|
||||||
raise ValueError(
|
raise ValueError(
|
||||||
f'"{section_name}" is not a valid section name. Please create a'
|
f'"{section_name}" is not a valid section name. Please create a'
|
||||||
" custom section with this name or delete it from the section"
|
" custom section with this name or delete it from the section"
|
||||||
" order."
|
" order 😷"
|
||||||
)
|
)
|
||||||
|
|
||||||
section = Section(
|
section = Section(
|
||||||
|
@ -1312,7 +1315,7 @@ class RenderCVDataModel(BaseModel):
|
||||||
if title not in section_titles:
|
if title not in section_titles:
|
||||||
raise ValueError(
|
raise ValueError(
|
||||||
f'The section "{title}" that is specified in the'
|
f'The section "{title}" that is specified in the'
|
||||||
' "show_timespan_in" option is not found in the CV! The'
|
' "show_timespan_in" option is not found in the CV 😱! The'
|
||||||
f" available section titles are: {section_titles}"
|
f" available section titles are: {section_titles}"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue