Skip to content

Commit

Permalink
derive: make syntax element errors more specific
Browse files Browse the repository at this point in the history
  • Loading branch information
djc committed Sep 19, 2024
1 parent 231dbb2 commit 3452243
Showing 1 changed file with 13 additions and 12 deletions.
25 changes: 13 additions & 12 deletions askama_derive/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,22 +148,23 @@ impl<'a> TryInto<Syntax<'a>> for RawSyntax<'a> {
comment_end: self.comment_end.unwrap_or(default.comment_end),
};

for s in [
syntax.block_start,
syntax.block_end,
syntax.expr_start,
syntax.expr_end,
syntax.comment_start,
syntax.comment_end,
for (s, kind) in [
(syntax.block_start, "block_start"),
(syntax.block_end, "block_end"),
(syntax.expr_start, "expr_start"),
(syntax.expr_end, "expr_end"),
(syntax.comment_start, "comment_start"),
(syntax.comment_end, "comment_end"),
] {
if s.len() < 2 {
return Err(
format!("delimiters must be at least two characters long: {s:?}").into(),
);
return Err(format!(
"{kind} delimiter must be at least two characters long: {s:?}"
)
.into());
} else if s.chars().any(|c| c.is_whitespace()) {
return Err(format!("delimiters may not contain white spaces: {s:?}").into());
return Err(format!("{kind} delimiter may not contain whitespace: {s:?}").into());
} else if TWO_PLUS_CHAR_OPS.contains(&s) {
return Err(format!("delimiters may not contain operators: {s:?}").into());
return Err(format!("{kind} delimiter may not contain operators: {s:?}").into());
}
}

Expand Down

0 comments on commit 3452243

Please sign in to comment.