From 59f0f8258a487f2d7da2e36df28685685f6dc1a8 Mon Sep 17 00:00:00 2001 From: ElnuDev Date: Wed, 24 May 2023 09:30:04 -0700 Subject: [PATCH] Improve error handling for Eat optional parameter --- renrs/src/lib.rs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/renrs/src/lib.rs b/renrs/src/lib.rs index d451396..0b6fd56 100644 --- a/renrs/src/lib.rs +++ b/renrs/src/lib.rs @@ -140,6 +140,11 @@ fn parse_file(file_path: PathBuf) -> Vec { let token_lines = tokenize_file(file_path); let mut commands = Vec::new(); for line in token_lines { + macro_rules! unknown { + () => { + panic!("Unknown command {}", describe_line(&line)) + }; + } commands.push(match line.as_slice() { [Str(text)] => Say { name: None, @@ -153,10 +158,10 @@ fn parse_file(file_path: PathBuf) -> Vec { food: food.to_owned(), politely: match tail { [Boolean(politely)] => *politely, - _ => false, + _ => unknown!(), }, }, - _ => panic!("Unknown command {}", describe_line(&line)), + _ => unknown!(), }); } commands