Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 11 additions & 8 deletions crates/metassr-build/src/server/manifest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,15 +92,18 @@ impl Manifest {
pub fn get(&self, route: &str) -> Option<&ManifestEntry> {
self.routes.get(route)
}
}

impl<S: AsRef<OsStr> + ?Sized> From<&S> for Manifest {
fn from(path: &S) -> Self {
let manifest_filename = "manifest.json";
let path = PathBuf::from(path).join(manifest_filename);
let content = read_to_string(path).unwrap();

serde_json::from_str(&content).unwrap()
/// Load manifest from path with proper error handling
pub fn load<S: AsRef<OsStr> + ?Sized>(path: &S) -> Result<Self> {
let path = PathBuf::from(path).join("manifest.json");
let content = read_to_string(&path).map_err(|e| {
anyhow!(
"Could not read manifest.json at {:?}: {}. Did you run `metassr build` first?",
path,
e
)
})?;
serde_json::from_str(&content).map_err(|e| anyhow!("manifest.json is malformed: {}", e))
}
}

Expand Down
9 changes: 6 additions & 3 deletions crates/metassr-build/src/server/renderer/page.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::ffi::OsStr;

use anyhow::Result;
use anyhow::{anyhow, Result};

use metassr_fs_analyzer::dist_dir::PageEntry;
use metassr_utils::cache_dir::CacheDir;
Expand All @@ -23,10 +23,13 @@ impl PageRenderer {
manifest_parent: &S,
route: &str,
) -> Result<Self> {
let manifest = Manifest::from(manifest_parent);
let manifest = Manifest::load(manifest_parent)?;

let cache = CacheDir::new(&manifest.global.cache)?;
let entry = manifest.get(route).unwrap().clone();
let entry = manifest
.get(route)
.ok_or_else(|| anyhow!("No manifest entry found for route: {:?}", route))?
.clone();

let exec = RenderExec::new(entry.id, &entry.renderer)?;
let body = exec.exec()?;
Expand Down