diff options
author | Guillaume Gomez <guillaume1.gomez@gmail.com> | 2023-11-17 11:47:39 +0100 |
---|---|---|
committer | Dirkjan Ochtman <dirkjan@ochtman.nl> | 2023-11-20 10:34:26 +0100 |
commit | 9de2336ab2506222369182b0f13be2165d43011c (patch) | |
tree | 5403382f6c577c89f5c8b4eeb98ba023914f0db7 /askama_derive | |
parent | 6cbfde04514a90d4e24350c21ef490c40666d820 (diff) | |
download | askama-9de2336ab2506222369182b0f13be2165d43011c.tar.gz askama-9de2336ab2506222369182b0f13be2165d43011c.tar.bz2 askama-9de2336ab2506222369182b0f13be2165d43011c.zip |
Improve output error for non-matching number of arguments for macros
Diffstat (limited to 'askama_derive')
-rw-r--r-- | askama_derive/src/generator.rs | 9 |
1 files changed, 8 insertions, 1 deletions
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 |