mirror of
https://github.com/askama-rs/askama.git
synced 2025-10-02 07:20:55 +00:00
Show error reason when template could not be read
This commit is contained in:
parent
55e8ff1d46
commit
6a6994670d
@ -302,21 +302,24 @@ pub(crate) fn get_template_source(
|
|||||||
tpl_path: &Path,
|
tpl_path: &Path,
|
||||||
import_from: Option<(&Rc<Path>, &str, &str)>,
|
import_from: Option<(&Rc<Path>, &str, &str)>,
|
||||||
) -> Result<String, CompileError> {
|
) -> Result<String, CompileError> {
|
||||||
if let Ok(mut source) = fs::read_to_string(tpl_path) {
|
match fs::read_to_string(tpl_path) {
|
||||||
|
Ok(mut source) => {
|
||||||
if source.ends_with('\n') {
|
if source.ends_with('\n') {
|
||||||
let _ = source.pop();
|
let _ = source.pop();
|
||||||
}
|
}
|
||||||
Ok(source)
|
Ok(source)
|
||||||
} else {
|
}
|
||||||
|
Err(err) => {
|
||||||
let msg = format!(
|
let msg = format!(
|
||||||
"unable to open template file '{}'",
|
"unable to open template file '{}': {err}",
|
||||||
tpl_path.to_str().unwrap()
|
tpl_path.to_str().unwrap(),
|
||||||
);
|
);
|
||||||
let file_info = import_from.map(|(node_file, file_source, node_source)| {
|
let file_info = import_from.map(|(node_file, file_source, node_source)| {
|
||||||
FileInfo::new(node_file, Some(file_source), Some(node_source))
|
FileInfo::new(node_file, Some(file_source), Some(node_source))
|
||||||
});
|
});
|
||||||
Err(CompileError::new(msg, file_info))
|
Err(CompileError::new(msg, file_info))
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static CONFIG_FILE_NAME: &str = "rinja.toml";
|
static CONFIG_FILE_NAME: &str = "rinja.toml";
|
||||||
|
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