Skip to content

Couldn't read template in strange symlink nested workspace #704

@shirok1

Description

@shirok1

Describe the bug
When referencing a crate depending askama with path in following strange symlink nested workspace structure, a couldn't read error will be emitted, which is different from what will be emitted in normal missing template cases template "xxx.jinja" not found in directories

To Reproduce

.
├── workspace-a
│   ├── Cargo.toml
│   └── crate-a
│       ├── Cargo.toml
│       ├── src
│       │   ├── lib.rs
│       └── templates
│           └── hello.jinja
└── workspace-b
    ├── Cargo.toml
    ├── crate-b
    │   ├── Cargo.toml
    │   └── src
    │       └── main.rs
    └── workspace-a-symlink -> ../workspace-a

workspace-a/crate-a/src/lib.rs:

use askama::Template; // bring trait in scope

#[derive(Template)]
#[template(path = "hello.jinja")]
struct HelloTemplate<'a> {
    name: &'a str,
}

pub fn hello() {
    let hello = HelloTemplate { name: "world" }; // instantiate your struct
    println!("{}", hello.render().unwrap()); // then render it.
    eprintln!("{}", hello.render().unwrap()); // then render it.
}

workspace-b/crate-b/Cargo.toml:

[package]
name = "crate-b"
version = "0.1.0"
edition = "2024"

[dependencies]
crate-a = { path = "../workspace-a-symlink/crate-a" }

Running cargo build in workspace b with hello.jinja exists:

   Compiling crate-a v0.1.0 (/Users/qinzezhao/Code/oss/askama-test/workspace-b/workspace-a-symlink/crate-a)
error: couldn't read `workspace-a-symlink/crate-a/src/../../../../workspace-a/crate-a/templates/hello.jinja`: No such file or directory (os error 2)
 --> workspace-a-symlink/crate-a/src/lib.rs:3:10
  |
3 | #[derive(Template)]
  |          ^^^^^^^^

error: could not compile `crate-a` (lib) due to 1 previous error

Running cargo build in workspace b with hello.jinja NOT existing (e.g. renaming it to something else):

   Compiling crate-a v0.1.0 (/Users/qinzezhao/Code/oss/askama-test/workspace-b/workspace-a-symlink/crate-a)
error: template "hello.jinja" not found in directories ["/Users/qinzezhao/Code/oss/askama-test/workspace-b/workspace-a-symlink/crate-a/templates"]
 --> workspace-a-symlink/crate-a/src/lib.rs:4:19
  |
4 | #[template(path = "hello.jinja")]
  |                   ^^^^^^^^^^^^^

error: could not compile `crate-a` (lib) due to 1 previous error

Askama version
0.15.4

Rust version
1.92.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions