mirror of
https://github.com/askama-rs/askama.git
synced 2025-09-28 05:21:14 +00:00
Merge pull request #46 from Kijewski/pr-one-less-allow
Remove a `#[allow(clippy::match_wild_err_arm)]` and dedup error message creation
This commit is contained in:
commit
e3c1fe3548
@ -298,38 +298,27 @@ where
|
||||
vals.iter().map(|s| s.to_string()).collect()
|
||||
}
|
||||
|
||||
#[allow(clippy::match_wild_err_arm)]
|
||||
pub(crate) fn get_template_source(
|
||||
tpl_path: &Path,
|
||||
import_from: Option<(&Rc<Path>, &str, &str)>,
|
||||
) -> std::result::Result<String, CompileError> {
|
||||
) -> Result<String, CompileError> {
|
||||
match fs::read_to_string(tpl_path) {
|
||||
Err(_) => {
|
||||
if let Some((node_file, file_source, node_source)) = import_from {
|
||||
Err(CompileError::new(
|
||||
format!(
|
||||
"unable to open template file '{}'",
|
||||
tpl_path.to_str().unwrap(),
|
||||
),
|
||||
Some(FileInfo::new(
|
||||
node_file,
|
||||
Some(file_source),
|
||||
Some(node_source),
|
||||
)),
|
||||
))
|
||||
} else {
|
||||
Err(CompileError::no_file_info(format!(
|
||||
"unable to open template file '{}'",
|
||||
tpl_path.to_str().unwrap()
|
||||
)))
|
||||
}
|
||||
}
|
||||
Ok(mut source) => {
|
||||
if source.ends_with('\n') {
|
||||
let _ = source.pop();
|
||||
}
|
||||
Ok(source)
|
||||
}
|
||||
Err(err) => {
|
||||
let msg = format!(
|
||||
"unable to open template file '{}': {err}",
|
||||
tpl_path.to_str().unwrap(),
|
||||
);
|
||||
let file_info = import_from.map(|(node_file, file_source, node_source)| {
|
||||
FileInfo::new(node_file, Some(file_source), Some(node_source))
|
||||
});
|
||||
Err(CompileError::new(msg, file_info))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
2
testing/templates/a_file_that_is_actually_a_folder.html/.gitignore
vendored
Normal file
2
testing/templates/a_file_that_is_actually_a_folder.html/.gitignore
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
*
|
||||
!.gitignore
|
8
testing/tests/ui/include-a-folder.rs
Normal file
8
testing/tests/ui/include-a-folder.rs
Normal file
@ -0,0 +1,8 @@
|
||||
use rinja::Template;
|
||||
|
||||
#[derive(Template)]
|
||||
#[template(ext = "txt", source = r#"{% include "a_file_that_is_actually_a_folder.html" %}"#)]
|
||||
struct YouCannotIncludeFolders;
|
||||
|
||||
fn main() {
|
||||
}
|
9
testing/tests/ui/include-a-folder.stderr
Normal file
9
testing/tests/ui/include-a-folder.stderr
Normal file
@ -0,0 +1,9 @@
|
||||
error: unable to open template file '$WORKSPACE/target/tests/trybuild/rinja_testing/templates/a_file_that_is_actually_a_folder.html': Is a directory (os error 21)
|
||||
--> YouCannotIncludeFolders.txt:1:2
|
||||
" include \"a_file_that_is_actually_a_fold"...
|
||||
--> tests/ui/include-a-folder.rs:3:10
|
||||
|
|
||||
3 | #[derive(Template)]
|
||||
| ^^^^^^^^
|
||||
|
|
||||
= note: this error originates in the derive macro `Template` (in Nightly builds, run with -Z macro-backtrace for more info)
|
Loading…
x
Reference in New Issue
Block a user