pallets/jinja

PackageLoader raises misleading error when template directory does not exist.

elektito opened this issue · 2 comments

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:

  • Python version: 3.10.12
  • Jinja version: 3.1.4

Happy to review a PR

Done!