From 481b08d9297e16e7c8eb29defc1a8b3302b937e5 Mon Sep 17 00:00:00 2001 From: Federico Igne Date: Fri, 30 Dec 2022 15:36:23 +0000 Subject: qol: print name of missing macro on panic --- README.md | 5 ++--- src/main.rs | 5 ++--- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index b876bb8..94f4a43 100644 --- a/README.md +++ b/README.md @@ -441,7 +441,7 @@ In case we reach the maximum allowed depth we truncate code block substitution a if current_depth < max_depth { let block = blocks .get(&Key::Macro(caps[2].to_string())) - .expect("Block not present") + .unwrap_or_else(|| panic!("Block \"{}\" not present", caps[2].to_string())) .clone(); indent(block, caps[1].len()) } else { @@ -521,8 +521,7 @@ let file = base .clone() .unwrap_or(PathBuf::from(BASE)) .join(path); -write_to_file(file, &code) - .expect("Unable to write to file"); +write_to_file(file, &code).unwrap(); ``` ## Additional details diff --git a/src/main.rs b/src/main.rs index 8168ad8..1d6bdd4 100644 --- a/src/main.rs +++ b/src/main.rs @@ -70,7 +70,7 @@ fn build( if current_depth < max_depth { let block = blocks .get(&Key::Macro(caps[2].to_string())) - .expect("Block not present") + .unwrap_or_else(|| panic!("Block \"{}\" not present", caps[2].to_string())) .clone(); indent(block, caps[1].len()) } else { @@ -88,8 +88,7 @@ fn build( .clone() .unwrap_or(PathBuf::from(BASE)) .join(path); - write_to_file(file, &code) - .expect("Unable to write to file"); + write_to_file(file, &code).unwrap(); }) } -- cgit v1.2.3