Keats / tera

A template engine for Rust based on Jinja2/Django
http://keats.github.io/tera/
MIT License
3.36k stars 280 forks source link

More complete Display implementation for Error #915

Open Thomasdezeeuw opened 2 months ago

Thomasdezeeuw commented 2 months ago

We've been hitting some template errors, usually nothing major, but the error message were never very useful. Usually they are just Failed to render '$FILE'", that's it. I just realised that Error actually contains more information, for example Variable `$VAR` not found in context while rendering '$FILE'. However we've missed those complete because we print out error using {}, i.e. the standard way of printing error.

Could Error::source also be included in the Display implementation of Error? This would make debug a whole lot easier for us.

Keats commented 2 months ago

I don't remember why it's done that way tbh

Thomasdezeeuw commented 2 months ago

Would you accept a pr to include the source information in the Display implementation?

Keats commented 2 months ago

I'm not sure, would that be considered a breaking change?

Thomasdezeeuw commented 2 months ago

I'm not sure, would that be considered a breaking change?

It's hard to say. I think the worse case is if people already worked around this issue and printed the source error themselves, leading to the source error being printed twice. Which, while not ideal, isn't the end of the world either?

Keats commented 2 months ago

I think i'd consider a breaking change but mostly for the end user. If it's included in Display, we will see the source errors twice for apps that did a workaround as you say. I'd prefer keeping that change for the next breaking version