Reduce use of expect in main.rs
This commit is contained in:
parent
7df393f31d
commit
823c33ef8e
14
src/main.rs
14
src/main.rs
@ -39,16 +39,15 @@ fn main_body() -> Result<(), Box<dyn std::error::Error>> {
|
|||||||
run_compare(
|
run_compare(
|
||||||
std::env::args()
|
std::env::args()
|
||||||
.nth(1)
|
.nth(1)
|
||||||
.expect("Pass a single file into this script."),
|
.ok_or("Pass a single file into this script.")?,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "compare")]
|
#[cfg(feature = "compare")]
|
||||||
fn run_compare<P: AsRef<Path>>(todo_org_path: P) -> Result<(), Box<dyn std::error::Error>> {
|
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 (remaining, rust_parsed) = document(org_contents.as_str()).expect("Org Parse failure");
|
||||||
let org_sexp =
|
let org_sexp = emacs_parse_org_document(todo_org_path.as_ref())?;
|
||||||
emacs_parse_org_document(todo_org_path.as_ref()).expect("Use emacs to parse org file.");
|
|
||||||
let (_remaining, parsed_sexp) =
|
let (_remaining, parsed_sexp) =
|
||||||
sexp_with_padding(org_sexp.as_str()).expect("Sexp Parse failure");
|
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);
|
println!("{:#?}", rust_parsed);
|
||||||
|
|
||||||
// We do the diffing after printing out both parsed forms in case the diffing panics
|
// We do the diffing after printing out both parsed forms in case the diffing panics
|
||||||
let diff_result =
|
let diff_result = compare_document(&parsed_sexp, &rust_parsed)?;
|
||||||
compare_document(&parsed_sexp, &rust_parsed).expect("Compare parsed documents.");
|
diff_result.print()?;
|
||||||
diff_result
|
|
||||||
.print()
|
|
||||||
.expect("Print document parse tree diff.");
|
|
||||||
|
|
||||||
if diff_result.is_bad() {
|
if diff_result.is_bad() {
|
||||||
Err("Diff results do not match.")?;
|
Err("Diff results do not match.")?;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user