djc / askama

Type-safe, compiled Jinja-like templates for Rust
Apache License 2.0
3.35k stars 215 forks source link

Improve error message by providing the file where the error occurred if it is not an inlined source #986

Closed GuillaumeGomez closed 5 months ago

GuillaumeGomez commented 5 months ago

When you have templates included in templates, the errors become quite difficult to understand as we don't know which file is triggering it. With this change, it adds the path of the file where the error is located:

error: problems parsing template source in `templates/core/about/builds.html` at row 34, column 32 near:
       "=\"rust\") %}{% filter dedent(levels=3) -%"...
   --> src/web/sitemap.rs:109:10
    |
109 | #[derive(Template)]
    |          ^^^^^^^^
    |
    = note: this error originates in the derive macro `Template` (in Nightly builds, run with -Z macro-backtrace for more info)

Making my life and very likely everyone else's better. :)

Sadly, I can't enforce it with trybuild as it only allows to have inline tests (because the folder where the ui tests are run is different and I couldn't find a way to do it...).

GuillaumeGomez commented 5 months ago

Finally made tests work on CI. \o/

I added a ui test as well (took me more time than I expected...).

GuillaumeGomez commented 5 months ago

Updated!

GuillaumeGomez commented 5 months ago

Rebased on #994.

GuillaumeGomez commented 5 months ago

Thanks for the reviews! Merging then. :)