New issue

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

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

Already on GitHub? Sign in to your account

when renderer is not supported, report back what is missing #81

Closed
alfredodeza opened this Issue Sep 8, 2016 · 0 comments

Comments

Projects
None yet
1 participant
@alfredodeza
Copy link
Contributor

alfredodeza commented Sep 8, 2016

Had some issues trying to use jinja2 as renderer but was getting the following traceback:

...
File ".../pecan/core.py", line 421, in render
    return renderer.render(template, namespace)
AttributeError: 'NoneType' object has no attribute 'render'

This was because jinja2 is not the right name for the renderer.

The following change in core.py would report this with more useful information:

diff --git a/pecan/core.py b/pecan/core.py
index f02b3a3..3f7f211 100644
--- a/pecan/core.py
+++ b/pecan/core.py
@@ -412,6 +412,8 @@ class PecanBase(object):
                 renderer_name,
                 self.template_path
             )
+            if renderer is None:
+                raise RuntimeError('template support for %s was not found' % renderer_name)
         else:
             renderer = self.renderers.get(
                 self.default_renderer,

The test case demonstrates the more informative error:

diff --git a/pecan/tests/test_base.py b/pecan/tests/test_base.py
index 435e8b5..2180d47 100644
--- a/pecan/tests/test_base.py
+++ b/pecan/tests/test_base.py
@@ -1898,6 +1898,27 @@ class TestEngines(PecanTestCase):
                     break
         assert error_msg is not None

+    def test_renderer_not_found(self):
+
+        class RootController(object):
+            @expose('mako3:mako.html')
+            def index(self, name='Jonathan'):
+                return dict(name=name)
+
+            @expose('mako3:mako_bad.html')
+            def badtemplate(self):
+                return dict()
+
+        app = TestApp(
+            Pecan(RootController(), template_path=self.template_path)
+        )
+        try:
+            r = app.get('/')
+        except Exception as e:
+            expected = e
+
+        assert str(expected) == "template support for mako3 was not found"
+
     def test_json(self):
         try:
             from simplejson import loads

There are also other things in that core.py block that could be used for the error reporting, like the path. It is not uncommon to tell pecan to look at a certain path where a given template doesn't exist, but nothing (currently) points to where that may be.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment