mirror of
https://github.com/askama-rs/askama.git
synced 2025-09-27 13:00:57 +00:00
Improve error output
This commit is contained in:
parent
aefd0848af
commit
1acbc33383
@ -1127,10 +1127,14 @@ impl<'a> Generator<'a, '_> {
|
||||
ctx: &Context<'a>,
|
||||
expected: usize,
|
||||
found: usize,
|
||||
name: &str,
|
||||
) -> Result<(), CompileError> {
|
||||
if expected != found {
|
||||
Err(ctx.generate_error(
|
||||
format!("expected `{}` argument, found `{}`", expected, found),
|
||||
format!(
|
||||
"expected {expected} argument{} in `{name}`, found {found}",
|
||||
if expected != 1 { "s" } else { "" }
|
||||
),
|
||||
s.span(),
|
||||
))
|
||||
} else {
|
||||
@ -1138,11 +1142,11 @@ impl<'a> Generator<'a, '_> {
|
||||
}
|
||||
}
|
||||
if ***path == Expr::Var("super") {
|
||||
check_num_args(s, ctx, 0, expr_args.len())?;
|
||||
check_num_args(s, ctx, 0, expr_args.len(), "super")?;
|
||||
return self.write_block(ctx, buf, None, ws, s.span());
|
||||
} else if ***path == Expr::Var("caller") {
|
||||
let def = self.active_caller.ok_or_else(|| {
|
||||
ctx.generate_error(format_args!("block is not defined for caller"), s.span())
|
||||
ctx.generate_error(format_args!("block is not defined for `caller`"), s.span())
|
||||
})?;
|
||||
self.active_caller = None;
|
||||
self.handle_ws(ws);
|
||||
@ -1151,7 +1155,7 @@ impl<'a> Generator<'a, '_> {
|
||||
buf.write('{');
|
||||
this.prepare_ws(def.ws1);
|
||||
let mut value = Buffer::new();
|
||||
check_num_args(s, ctx, def.caller_args.len(), expr_args.len())?;
|
||||
check_num_args(s, ctx, def.caller_args.len(), expr_args.len(), "caller")?;
|
||||
for (index, arg) in def.caller_args.iter().enumerate() {
|
||||
match expr_args.get(index) {
|
||||
Some(expr) => {
|
||||
|
@ -1,4 +1,4 @@
|
||||
error: expected `3` argument, found `2`
|
||||
error: expected 3 arguments in `caller`, found 2
|
||||
--> InvalidNumberArguments.txt:3:18
|
||||
"(\"a\", \"b\") -}}\n {%- endmacro -%}\n {%- call(a,b,c) test() -%}\n {{- a"...
|
||||
--> tests/ui/caller_arguments.rs:5:14
|
||||
@ -13,85 +13,85 @@ error: expected `3` argument, found `2`
|
||||
12 | | "#,
|
||||
| |______^
|
||||
|
||||
error: expected `1` argument, found `2`
|
||||
error: expected 1 argument in `caller`, found 2
|
||||
--> InvalidNumberArguments1.txt:3:18
|
||||
"(\"a\", \"b\") -}}\n {%- endmacro -%}\n {%- call(a) test() -%}\n {{- a -}}"...
|
||||
--> tests/ui/caller_arguments.rs:21:14
|
||||
--> tests/ui/caller_arguments.rs:20:14
|
||||
|
|
||||
21 | source = r#"
|
||||
20 | source = r#"
|
||||
| ______________^
|
||||
22 | | {% macro test() %}
|
||||
23 | | {{- caller("a", "b") -}}
|
||||
24 | | {%- endmacro -%}
|
||||
21 | | {% macro test() %}
|
||||
22 | | {{- caller("a", "b") -}}
|
||||
23 | | {%- endmacro -%}
|
||||
... |
|
||||
27 | | {%- endcall -%}
|
||||
28 | | "#,
|
||||
26 | | {%- endcall -%}
|
||||
27 | | "#,
|
||||
| |______^
|
||||
|
||||
error: expected `)` to close call argument list
|
||||
--> <source attribute>:5:15
|
||||
"test() -%}\n {{- a -}}\n {%- endcall -%}\n "
|
||||
--> tests/ui/caller_arguments.rs:36:14
|
||||
--> tests/ui/caller_arguments.rs:35:14
|
||||
|
|
||||
36 | source = r#"
|
||||
35 | source = r#"
|
||||
| ______________^
|
||||
37 | | {% macro test() %}
|
||||
38 | | {{- caller("a") -}}
|
||||
39 | | {%- endmacro -%}
|
||||
36 | | {% macro test() %}
|
||||
37 | | {{- caller("a") -}}
|
||||
38 | | {%- endmacro -%}
|
||||
... |
|
||||
42 | | {%- endcall -%}
|
||||
43 | | "#,
|
||||
41 | | {%- endcall -%}
|
||||
42 | | "#,
|
||||
| |______^
|
||||
|
||||
error: block is not defined for caller
|
||||
error: block is not defined for `caller`
|
||||
--> CallerInCaller.txt:6:18
|
||||
"(a) -}}\n {%- endcall -%}\n "
|
||||
--> tests/ui/caller_arguments.rs:51:14
|
||||
--> tests/ui/caller_arguments.rs:50:14
|
||||
|
|
||||
51 | source = r#"
|
||||
50 | source = r#"
|
||||
| ______________^
|
||||
52 | | {% macro test() %}
|
||||
53 | | {{- caller("a") -}}
|
||||
54 | | {%- endmacro -%}
|
||||
51 | | {% macro test() %}
|
||||
52 | | {{- caller("a") -}}
|
||||
53 | | {%- endmacro -%}
|
||||
... |
|
||||
57 | | {%- endcall -%}
|
||||
58 | | "#,
|
||||
56 | | {%- endcall -%}
|
||||
57 | | "#,
|
||||
| |______^
|
||||
|
||||
error: block is not defined for caller
|
||||
error: block is not defined for `caller`
|
||||
--> CallerInCaller1.txt:10:21
|
||||
"(\"b\") }}\n {% endcall %}\n {{- a -}}\n {%- endcall -%}\n "
|
||||
--> tests/ui/caller_arguments.rs:66:14
|
||||
--> tests/ui/caller_arguments.rs:65:14
|
||||
|
|
||||
66 | source = r#"
|
||||
65 | source = r#"
|
||||
| ______________^
|
||||
67 | | {% macro test2() %}
|
||||
68 | | {{ caller("bb") }}
|
||||
69 | | {% endmacro %}
|
||||
66 | | {% macro test2() %}
|
||||
67 | | {{ caller("bb") }}
|
||||
68 | | {% endmacro %}
|
||||
... |
|
||||
78 | | {%- endcall -%}
|
||||
79 | | "#,
|
||||
77 | | {%- endcall -%}
|
||||
78 | | "#,
|
||||
| |______^
|
||||
|
||||
error: block is not defined for caller
|
||||
error: block is not defined for `caller`
|
||||
--> JustCaller.txt:1:8
|
||||
"()}}"
|
||||
--> tests/ui/caller_arguments.rs:87:14
|
||||
--> tests/ui/caller_arguments.rs:86:14
|
||||
|
|
||||
87 | source = r#"{{caller()}}"#,
|
||||
86 | source = r#"{{caller()}}"#,
|
||||
| ^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: failed to parse template source
|
||||
--> <source attribute>:3:27
|
||||
"= \"b\") }}\n {%- endmacro -%}\n {%- call(two, one) test() -%}\n {{- two"...
|
||||
--> tests/ui/caller_arguments.rs:95:14
|
||||
--> tests/ui/caller_arguments.rs:94:14
|
||||
|
|
||||
95 | source = r#"
|
||||
94 | source = r#"
|
||||
| ______________^
|
||||
96 | | {% macro test() %}
|
||||
97 | | {{ caller("a", one = "b") }}
|
||||
98 | | {%- endmacro -%}
|
||||
95 | | {% macro test() %}
|
||||
96 | | {{ caller("a", one = "b") }}
|
||||
97 | | {%- endmacro -%}
|
||||
... |
|
||||
101 | | {%- endcall -%}
|
||||
102 | | "#,
|
||||
100 | | {%- endcall -%}
|
||||
101 | | "#,
|
||||
| |______^
|
||||
|
Loading…
x
Reference in New Issue
Block a user