Skip to content

Commit

Permalink
if TOML header fails to parse, don't 500 the entire site
Browse files Browse the repository at this point in the history
Signed-off-by: Matt Butcher <[email protected]>
  • Loading branch information
technosophos committed Feb 25, 2022
1 parent 8350426 commit 82a4a12
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions src/content.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,17 @@ pub fn all_pages(dir: PathBuf, show_unpublished: bool) -> anyhow::Result<BTreeMa
continue;
}
let raw_data = std::fs::read_to_string(&f).map_err(|e| anyhow::anyhow!("File is not string data: {:?}: {}", &f, e))?;
let content: Content = raw_data.parse().map_err(|e|anyhow::anyhow!("File {:?}: {}", &f, e))?;
if show_unpublished || content.published {
contents.insert(f.to_string_lossy().to_string(), content.into());
match raw_data.parse::<Content>() {
Ok(content) => {
if show_unpublished || content.published {
contents.insert(f.to_string_lossy().to_string(), content.into());
}
},
Err(e) => {
// If a parse fails, don't take down the entire site. Just skip this piece of content.
eprintln!("File {:?}: {}", &f, e);
continue
}
}
}
Ok(contents)
Expand Down

0 comments on commit 82a4a12

Please sign in to comment.