Skip to content

Commit

Permalink
better error when a template is missing
Browse files Browse the repository at this point in the history
  • Loading branch information
jesseditson committed Jun 21, 2024
1 parent 25fadda commit 80f8725
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/site.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ pub enum InvalidFileError {
UnrecognizedType(String),
#[error("cannot define both {0} and {1}")]
DuplicateObjectDefinition(String, String),
#[error("template file {0} does not exist.")]
MissingTemplate(String),
}

#[derive(Debug, Deserialize, Serialize)]
Expand Down Expand Up @@ -279,6 +281,12 @@ impl Site {
if let Some(template) = &object_def.template {
let template_path = pages_dir.join(format!("{}.liquid", template));
debug!("rendering template objects for {}", template_path.display());
if !fs.exists(&template_path)? {
return Err(InvalidFileError::MissingTemplate(
template_path.display().to_string(),
)
.into());
}
let template_r = fs.read_to_string(&template_path);
if template_r.is_err() {
warn!("failed rendering {}", template_path.display());
Expand Down

0 comments on commit 80f8725

Please sign in to comment.