From 190cba1f3ad0be64f2e9f7938914669417f3d177 Mon Sep 17 00:00:00 2001 From: zyl Date: Thu, 7 Nov 2024 17:20:43 -0800 Subject: [PATCH] make `SiteBuilder` creation fallible --- src/builder.rs | 9 ++++----- src/lib.rs | 2 +- src/serving.rs | 2 +- 3 files changed, 6 insertions(+), 7 deletions(-) diff --git a/src/builder.rs b/src/builder.rs index ba2ecd2..29094f0 100644 --- a/src/builder.rs +++ b/src/builder.rs @@ -54,7 +54,7 @@ pub struct SiteBuilder { impl SiteBuilder { /// Creates a new site builder. - pub fn new(site: Site, serving: bool) -> Self { + pub fn new(site: Site, serving: bool) -> eyre::Result { let mut build_path = match &site.config.build { Some(build) => site.site_path.join(build), _ => site.site_path.join("build"), @@ -68,11 +68,10 @@ impl SiteBuilder { .join(format!("{}/**/*.tera", crate::TEMPLATES_PATH)) .to_str() .expect("failed to convert path to string"), - ) - .expect("failed to create tera instance"); + )?; tera.autoescape_on(vec![".tera"]); - Self { + Ok(Self { tera, syntax_set: SyntaxSet::load_defaults_newlines(), theme_set: ThemeSet::load_defaults(), @@ -80,7 +79,7 @@ impl SiteBuilder { site, build_path, serving, - } + }) } /// Prepares the site builder for use and sets up the build directory. diff --git a/src/lib.rs b/src/lib.rs index 8089ec7..e9c2620 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -159,7 +159,7 @@ impl Site { /// Builds the site once. pub fn build_once(self) -> eyre::Result<()> { - let builder = SiteBuilder::new(self, false).prepare()?; + let builder = SiteBuilder::new(self, false)?.prepare()?; builder.site.build_all_pages(&builder)?; builder.build_sass()?; diff --git a/src/serving.rs b/src/serving.rs index 75dc751..69c7da2 100644 --- a/src/serving.rs +++ b/src/serving.rs @@ -150,7 +150,7 @@ impl Site { pub async fn serve(self) -> eyre::Result<()> { let addr = SocketAddr::from(([127, 0, 0, 1], 8080)); - let mut builder = SiteBuilder::new(self, true).prepare()?; + let mut builder = SiteBuilder::new(self, true)?.prepare()?; let site = &builder.site; let build_path = builder.build_path.clone();