Reduce use of expect in main.rs

This commit is contained in:
Tom Alexander 2023-08-16 16:37:14 -04:00
parent 7df393f31d
commit 823c33ef8e
Signed by: talexander
GPG Key ID: D3A179C9A53C0EDE

View File

@ -39,16 +39,15 @@ fn main_body() -> Result<(), Box<dyn std::error::Error>> {
run_compare(
std::env::args()
.nth(1)
.expect("Pass a single file into this script."),
.ok_or("Pass a single file into this script.")?,
)
}
#[cfg(feature = "compare")]
fn run_compare<P: AsRef<Path>>(todo_org_path: P) -> Result<(), Box<dyn std::error::Error>> {
let org_contents = std::fs::read_to_string(todo_org_path.as_ref()).expect("Read org file.");
let org_contents = std::fs::read_to_string(todo_org_path.as_ref())?;
let (remaining, rust_parsed) = document(org_contents.as_str()).expect("Org Parse failure");
let org_sexp =
emacs_parse_org_document(todo_org_path.as_ref()).expect("Use emacs to parse org file.");
let org_sexp = emacs_parse_org_document(todo_org_path.as_ref())?;
let (_remaining, parsed_sexp) =
sexp_with_padding(org_sexp.as_str()).expect("Sexp Parse failure");
@ -57,11 +56,8 @@ fn run_compare<P: AsRef<Path>>(todo_org_path: P) -> Result<(), Box<dyn std::erro
println!("{:#?}", rust_parsed);
// We do the diffing after printing out both parsed forms in case the diffing panics
let diff_result =
compare_document(&parsed_sexp, &rust_parsed).expect("Compare parsed documents.");
diff_result
.print()
.expect("Print document parse tree diff.");
let diff_result = compare_document(&parsed_sexp, &rust_parsed)?;
diff_result.print()?;
if diff_result.is_bad() {
Err("Diff results do not match.")?;