Exceptions thrown in NewRequest subscriber don't get caught by pyramid_debugtoolbar

62 views
Skip to first unread message

Wyatt Baldwin

unread,
Feb 13, 2013, 1:45:47 PM2/13/13
to pylons-...@googlegroups.com
I have a NewRequest subscriber that's added in main() via config.add_subscriber(). Exceptions thrown in this subscriber aren't caught by pyramid_debugtoolbar. Is this behavior expected?

Michael Merickel

unread,
Feb 13, 2013, 2:15:48 PM2/13/13
to Pylons
Without more info I can say it's not expected on anything after Pyramid 1.0 where NewRequest subscribers explicitly did not support exceptions.


On Wed, Feb 13, 2013 at 12:45 PM, Wyatt Baldwin <wyatt.le...@gmail.com> wrote:
I have a NewRequest subscriber that's added in main() via config.add_subscriber(). Exceptions thrown in this subscriber aren't caught by pyramid_debugtoolbar. Is this behavior expected?

--
You received this message because you are subscribed to the Google Groups "pylons-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pylons-discus...@googlegroups.com.
To post to this group, send email to pylons-...@googlegroups.com.
Visit this group at http://groups.google.com/group/pylons-discuss?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Wyatt Baldwin

unread,
Feb 13, 2013, 4:40:00 PM2/13/13
to pylons-...@googlegroups.com
I'm using Pyramid 1.4. pyramid_debugtoolbar is included via the pyramid.includes settings. I'm not using any other includes or tweens. The subscriber is set up like this:

def main(global_config, *settings):
    config = Configurator(settings=settings)
    def callback(event):
        """Exceptions raised here are not caught by pyramid_debugtoolbar"""
    config.add_subscriber(callback, NewRequest)
    app = config.make_wsgi_app()
    return app

Wyatt Baldwin

unread,
Feb 13, 2013, 5:25:02 PM2/13/13
to pylons-...@googlegroups.com
I created a minimal test case. The exception raised by the view is caught by pyramid_debugtoolbar. The exception raised by the NewRequest callback is caught but isn't displayed correctly because requests to /_debug_toolbar/* hit the same exception.

I can fix this by returning early from the callback if PATH_INFO starts with /_debug_toolbar, but maybe there's a better way.

But this is a bit different from what I'm seeing in my actual app, which is that the exeption doesn't appear to be caught at all. More investigation under way...


from waitress import serve

from pyramid.config import Configurator
from pyramid.events import NewRequest


def main(global_config, **settings):
settings['pyramid.includes'] = ['pyramid_debugtoolbar']

config = Configurator(settings=settings)
def callback(event):
        something()
#config.add_subscriber(callback, NewRequest)
config.add_route('route', '/route')
config.add_view(view, route_name='route', renderer='string')

app = config.make_wsgi_app()
return app


def view(request):
return xxx


def something():
raise Exception


if __name__ == '__main__':
app = main({})
serve(app)

Michael Merickel

unread,
Feb 13, 2013, 7:00:22 PM2/13/13
to Pylons
Oh.. that.. yeah. Without providing any useful information, I can just say that I tend to avoid NewRequest subscribers like the plague now that config.add_request_method exists.

This sounds like a more fundamental issue with the toolbar. It historically causes all sorts of odd problems that some of its urls are handled within your Pyramid application.
Reply all
Reply to author
Forward
0 new messages