From 9de2336ab2506222369182b0f13be2165d43011c Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Fri, 17 Nov 2023 11:47:39 +0100 Subject: Improve output error for non-matching number of arguments for macros --- askama_derive/src/generator.rs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'askama_derive/src') diff --git a/askama_derive/src/generator.rs b/askama_derive/src/generator.rs index eb293b0..abd16d5 100644 --- a/askama_derive/src/generator.rs +++ b/askama_derive/src/generator.rs @@ -719,11 +719,18 @@ impl<'a> Generator<'a> { let mut names = Buffer::new(0); let mut values = Buffer::new(0); let mut is_first_variable = true; + if args.len() != def.args.len() { + return Err(CompileError::from(format!( + "macro {name:?} expected {} argument{}, found {}", + def.args.len(), + if def.args.len() != 1 { "s" } else { "" }, + args.len() + ))); + } for (i, arg) in def.args.iter().enumerate() { let expr = args.get(i).ok_or_else(|| { CompileError::from(format!("macro {name:?} takes more than {i} arguments")) })?; - match expr { // If `expr` is already a form of variable then // don't reintroduce a new variable. This is -- cgit