<div dir="ltr">Wow, thanks Miguel! I sure have been stumped on Mako errors before, this will really help.<div><br></div><div>Pascal</div><div><br></div></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Wed, Jun 11, 2014 at 5:51 AM, Miguel Colom <span dir="ltr"><<a href="mailto:colom@cmla.ens-cachan.fr" target="_blank">colom@cmla.ens-cachan.fr</a>></span> wrote:<br>

<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Dear all,<br>
since now, when it raised an exception during a Mako template rendering, CherryPy showed a traceback which in fact is not really informative. Most of the time, it shows just the name of the exception (nameError), but not which variable caused the problem or which file.<br>


<br>
I've modified base_app.py in order to use the RichTraceback() object from Mako. Now, when a unhandled template exception occurs, a different error page is shown, telling which file, line and contents of the line caused the failure.<br>


<br>
For example:<br>
File /home/miguel/ipolLocal/demo/<u></u>app/81/template/archive_index.<u></u>html, line 5, in render_body<br>
${nbpublic} public archives out of ${nbtotal} online experiments with<br>
<br>
In the example we can see that it was line #5 of file archive_index.html which caused the problem, involving the ${nbpublic} and ${nbtotal} variables.<br>
<br>
You can checkout the new code from git (best option), or change your tmpl_out(.) function by this one:<br>
    def tmpl_out(self, tmpl_fname, **kwargs):<br>
        """<br>
        templating shortcut, populated with the default app attributes<br>
        """<br>
        # pass the app object<br>
        kwargs['app'] = self<br>
        # production flag<br>
        kwargs['prod'] = (cherrypy.config['server.<u></u>environment']<br>
                          == 'production')<br>
<br>
        tmpl = self.tmpl_lookup.get_template(<u></u>tmpl_fname)<br>
<br>
        # Render the template<br>
        # If an exception occurs, render an error page showing the traceback<br>
        try:<br>
            return tmpl.render(**kwargs)<br>
        except:<br>
            traceback_string = "<h1>IPOL template rendering error</h1>"<br>
            traceback_string += "<h2>Template: %s</h2>" % tmpl_fname<br>
            traceback_string += "<h2>kwargs: %s</h2>" % kwargs<br>
            traceback = RichTraceback()<br>
            for (filename, lineno, function, line) in traceback.traceback:<br>
                traceback_string += \<br>
                    "File <b>%s</b>, line <b>%d</b>, in <b>%s</b><br>" % \<br>
                    (filename, lineno, function)<br>
                traceback_string += line + "<br><br>"<br>
            traceback_string += "%s: %s" % \<br>
                (str(traceback.error.__class__<u></u>.__name__), \<br>
                traceback.error) + "<br>"<br>
            return traceback_string<br>
<br>
(also add "from mako.exceptions import RichTraceback" before "from . import http").<br>
<br>
Best,<br>
Miguel<br>
<br>
<br>
--<br>
IPOL - Image Processing On Line   - <a href="http://ipol.im/" target="_blank">http://ipol.im/</a><br>
<br>
contact     <a href="mailto:edit@ipol.im" target="_blank">edit@ipol.im</a>          - <a href="http://www.ipol.im/meta/contact/" target="_blank">http://www.ipol.im/meta/<u></u>contact/</a><br>
news+feeds  twitter @IPOL_journal - <a href="http://www.ipol.im/meta/feeds/" target="_blank">http://www.ipol.im/meta/feeds/</a><br>
announces   <a href="mailto:announce@list.ipol.im" target="_blank">announce@list.ipol.im</a> - <a href="http://tools.ipol.im/mm/announce/" target="_blank">http://tools.ipol.im/mm/<u></u>announce/</a><br>
discussions <a href="mailto:discuss@list.ipol.im" target="_blank">discuss@list.ipol.im</a>  - <a href="http://tools.ipol.im/mm/discuss/" target="_blank">http://tools.ipol.im/mm/<u></u>discuss/</a><br>
</blockquote></div><br><br clear="all"><div><br></div>-- <br>Pascal Getreuer<br>CMLA, ENS Cachan<br><a href="mailto:getreuer@cmla.ens-cachan.fr" target="_blank">getreuer@cmla.ens-cachan.fr</a><br><a href="http://www.getreuer.info" target="_blank">www.getreuer.info</a>
</div>