From 88dc32cb4b0d0e883a26e6e18759bf4ee22a91e9 Mon Sep 17 00:00:00 2001 From: Armin Ronacher Date: Tue, 9 Feb 2010 01:27:57 +0100 Subject: [PATCH] PrefixLoader raises correct error message now. This fixes #358. --HG-- branch : trunk --- jinja2/loaders.py | 9 +++++++-- tests/test_old_bugs.py | 15 ++++++++++++++- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/jinja2/loaders.py b/jinja2/loaders.py index 7dda2ae..cfc738b 100644 --- a/jinja2/loaders.py +++ b/jinja2/loaders.py @@ -277,11 +277,16 @@ class PrefixLoader(BaseLoader): def get_source(self, environment, template): try: - prefix, template = template.split(self.delimiter, 1) + prefix, name = template.split(self.delimiter, 1) loader = self.mapping[prefix] except (ValueError, KeyError): raise TemplateNotFound(template) - return loader.get_source(environment, template) + try: + return loader.get_source(environment, name) + except TemplateNotFound: + # re-raise the exception with the correct fileame here. + # (the one that includes the prefix) + raise TemplateNotFound(template) class ChoiceLoader(BaseLoader): diff --git a/tests/test_old_bugs.py b/tests/test_old_bugs.py index 5e51391..1ff5a55 100644 --- a/tests/test_old_bugs.py +++ b/tests/test_old_bugs.py @@ -8,7 +8,8 @@ :copyright: (c) 2009 by the Jinja Team. :license: BSD. """ -from jinja2 import Template, Environment, DictLoader, TemplateSyntaxError +from jinja2 import Template, Environment, DictLoader, TemplateSyntaxError, \ + TemplateNotFound, PrefixLoader env = Environment() @@ -168,3 +169,15 @@ def test_recursive_loop_bug(): {% endfor %} {% endfor %} """) + + +def test_correct_prefix_loader_name(): + env = Environment(loader=PrefixLoader({ + 'foo': DictLoader({}) + })) + try: + env.get_template('foo/bar.html') + except TemplateNotFound, e: + assert e.name == 'foo/bar.html' + else: + assert False, 'expected error here' -- 2.26.2