Skip to content
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

improve error handling #2

Open
kofrasa opened this issue Aug 27, 2012 · 5 comments
Open

improve error handling #2

kofrasa opened this issue Aug 27, 2012 · 5 comments

Comments

@kofrasa
Copy link

kofrasa commented Aug 27, 2012

Problem

Currently, all mako exceptions are intercepted and wrapped by the TemplateError.
This is not too useful as the mako error messages are suppressed and the stack trace is not provided in an easily readable presentation.

Template errors will typically be dumped onto the browser to allow easy navigation of the call stack

Suggestion

Expose the underlying Mako errors as a callableTemplateError returning the stack trace as HTML.
Changes are shown below, with the extra imports

from flask.helpers import make_response
from mako.exceptions import html_error_template

class TemplateError(RuntimeError):
    """ A template has thrown an error during rendering. """
    def __init__(self, template):
        self.tb = RichTraceback()
        self.text = text_error_template().render()
        self.html = html_error_template().render()
        msg = "Error occurred while rendering template '{0}'"
        msg = msg.format(template.uri)
        super(TemplateError, self).__init__(msg)

    def __call__(self, environ, start_response):
        """Call the exception as WSGI application.

        :param environ: the WSGI environment.
        :param start_response: the response callable provided by the WSGI
                               server.
        """
        response = make_response(self.html)
        return response(environ, start_response)
@AnIrishDuck
Copy link
Collaborator

This might be a useful half measure. However, the full solution (translate werkzeug traceback so that the interactive debugger shows proper source, variables, etc) has been committed already (see 0b53723). This requires a minor change to werkzeug (see pallets/werkzeug#206) that hasn't been committed yet.

@jab
Copy link

jab commented Oct 21, 2015

Sorry to see this issue stalled for so long, this would be such a huge improvement!! Even if just the "half-measure" above were added.

@AnIrishDuck, looks like your PR was just a testcase and changelog entry away from getting merged, but it never happened (see pallets/werkzeug#206 (comment)). Are you still interested in this? And are you, @benselme, still maintaining this project?

I'd be happy to help with the remaining work, but first just want to ask how realistic it is that this will get any attention here and make it into a new release soon.

Thanks!

@jab
Copy link

jab commented Oct 21, 2015

Just applied the changes from https://github.com/mitsuhiko/werkzeug/pull/206/files to Werkzeug manually and it looks like flask-mako needs no further modification for this to work, amazing!

In that case, if my comment pallets/werkzeug#206 (comment) gets a response from the Werkzeug maintainers soon, I can volunteer to do the last bit of work to get that merged into Werkzeug, if you don't beat me to it.

@benselme
Copy link
Owner

I'm not really maintaining anything here but I'll be happy to make a release if it helps !

@jab
Copy link

jab commented Oct 22, 2015

Thanks @benselme! Fortunately it looks like all it will take before this issue can be closed is pallets/werkzeug#206 to be merged; flask-mako already has what it needs thanks to @AnIrishDuck's 0b53723. But great you're still able to make new releases! Looks like it's been 2 years since the last release, and since then #8 and #9 were fixed/added, so might be worth making a new release now?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants