Check for empty field values

This commit is contained in:
mo8it 2024-04-17 19:12:10 +02:00
parent d42a6e7415
commit d6bb27ec20

View file

@ -19,6 +19,9 @@ fn check_info_file_exercises(info_file: &InfoFile) -> Result<hashbrown::HashSet<
let mut paths = hashbrown::HashSet::with_capacity(info_file.exercises.len());
for exercise_info in &info_file.exercises {
if exercise_info.name.is_empty() {
bail!("Found an empty exercise name in `info.toml`");
}
if let Some(c) = forbidden_char(&exercise_info.name) {
bail!(
"Char `{c}` in the exercise name `{}` is not allowed",
@ -27,11 +30,18 @@ fn check_info_file_exercises(info_file: &InfoFile) -> Result<hashbrown::HashSet<
}
if let Some(dir) = &exercise_info.dir {
if dir.is_empty() {
bail!("Found an empty dir name in `info.toml`");
}
if let Some(c) = forbidden_char(dir) {
bail!("Char `{c}` in the exercise dir `{dir}` is not allowed");
}
}
if exercise_info.hint.is_empty() {
bail!("The exercise `{}` has an empty hint. Please provide a hint or at least tell the user why a hint isn't needed for this exercise", exercise_info.name);
}
if !names.insert(exercise_info.name.as_str()) {
bail!(
"The exercise name {} is duplicated. Exercise names must all be unique",