pallets / jinja

A very fast and expressive template engine.
https://jinja.palletsprojects.com
BSD 3-Clause "New" or "Revised" License
10.28k stars 1.61k forks source link

PackageLoader raises misleading error when template directory does not exist. #1995

Open elektito opened 4 months ago

elektito commented 4 months ago

When using PackageLoader and the template directory does not exist, it throws an error saying:

The 'foobar' package was not installed in a way that PackageLoader understands.

This is clearly incorrect. If the package is actually not there, we get an assertion error. I would say the error should be something like "Template directory was not found in package 'foobar'." or something along those lines.

Describe how to replicate the bug. Just create a package without the template directory. Try to pass that name of the package to PackageLoader causes the incorrect error to be thrown.

I hope this is not considered too trivial. It did cost me some time to figure out, and only after reading the source code, so I think it's worth changing to something that makes the root cause more apparent.

Environment:

davidism commented 4 months ago

Happy to review a PR

elektito commented 4 months ago

Done!