Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

PackageLoader gives misleading error when wrong path given #1725

Closed
Dreamsorcerer opened this issue Sep 25, 2022 · 4 comments
Closed

PackageLoader gives misleading error when wrong path given #1725

Dreamsorcerer opened this issue Sep 25, 2022 · 4 comments

Comments

@Dreamsorcerer
Copy link
Contributor

Dreamsorcerer commented Sep 25, 2022

Just spent 10 minutes trying to debug this error:

ValueError: The 'my_app' package was not installed in a way that PackageLoader understands.

The package is absolutely fine. I just set the path to a non-existing path, so this code was never run:
https://github.com/pallets/jinja/blob/main/src/jinja2/loaders.py#L318-L320

Maybe add an else to the for which raises a different error?

Or that piece of code could be simplified down to something like:

try:
    template_root = next(p for root in roots if os.path.isdir(p := os.path.join(root, package_path)))
except StopIteration:
    raise ValueError(f"Template path not found in package: {package_path}.")

Or if you convert everything to Path, that can be simplified to next(p for root in roots if (p := root / package_path).is_dir()).

@davidism
Copy link
Member

Duplicate of #1705

@davidism davidism marked this as a duplicate of #1705 Sep 26, 2022
@Dreamsorcerer
Copy link
Contributor Author

Ah, thanks, missed that one.

For a PR, would the else be the desired change, or would the suggested refactor be good (I note that it does use the controversial walrus operator)?

@davidism
Copy link
Member

There's already an open PR linked to that issue.

@Dreamsorcerer
Copy link
Contributor Author

OK, I think it's wrong though. Will leave some feedback.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jan 10, 2023
# for free to subscribe to this conversation on GitHub. Already have an account? #.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants