Skip to content

Commit

Permalink
add some more descriptive guards on file errors
Browse files Browse the repository at this point in the history
Signed-off-by: Ryan Brue <[email protected]>
  • Loading branch information
ryanabx committed Dec 19, 2024
1 parent ffe6448 commit e8d548e
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,17 +168,26 @@ fn generate_site_2(
output_dir.join(x_path.join("index.html").strip_prefix(&root_dir)?);
log::info!("Result path: {:?}", &result_path);
let _ = std::fs::create_dir_all(result_path.parent().unwrap());
std::fs::write(&result_path, html.as_bytes())?;
if let Err(e) = std::fs::write(&result_path, html.as_bytes()) {
log::error!("Could not write file to path {:?}: {}", &result_path, e);
anyhow::bail!(e);
}
}
} else if x_path.is_file() {
let result_path =
output_dir.join(x_path.with_extension("html").strip_prefix(&root_dir)?);
if x_path.extension().is_some_and(|ext| ext == "md") {
let md = fs::read_to_string(x_path)?;
let html = markdown::md_to_html(&md, x_path.parent().unwrap(), web_prefix)?;
std::fs::write(&result_path, html.as_bytes())?;
if let Err(e) = std::fs::write(&result_path, html.as_bytes()) {
log::error!("Could not write file to path {:?}: {}", &result_path, e);
anyhow::bail!(e);
}
} else {
std::fs::copy(x_path, &result_path)?;
if let Err(e) = std::fs::copy(x_path, &result_path) {
log::error!("Could not copy file from {:?} to {:?}: {}", x_path, &result_path, e);
anyhow::bail!(e);
}
}
}
}
Expand Down

0 comments on commit e8d548e

Please sign in to comment.