WebError EvalException

6 views
Skip to first unread message

NCRonB

unread,
Feb 28, 2011, 11:41:45 PM2/28/11
to circuits
I would like to use weberror.EvalException with circuits.web for
interactive web-based debugging. I've used it with Pylons and
CherryPy, but I can't figure out how to get it working with
circuits.web. I've tried various flavors of
wsgi.Gateway(EvalException) but either I get an exception from
EvalException or circuits.web shows its usual tracebook as though
EvalException isn't there at all.

Any idea how to get it working (if it can)?

James Mills

unread,
Mar 1, 2011, 12:45:38 AM3/1/11
to circuit...@googlegroups.com
Hello,

Not really knowing anything about weberror I can't really comment.

However: What is weberror, what is EvalException ?

The circuits.web.wsgi.Gateway component
accepts as it's argument 2 things:
 * a path to mount the WSGI application on
 * the WSGI application callable

Please see the tests/web for how this work.

cheers
James

Justin Giorgi

unread,
Mar 1, 2011, 12:47:08 AM3/1/11
to circuit...@googlegroups.com

I have never used it myself but I would imagine that you could handle the exception event with a filter to prevent circuits from throwing it's traceback.

On Feb 28, 2011 9:43 PM, "NCRonB" <ronbi...@gmail.com> wrote:

NCRonB

unread,
Mar 1, 2011, 1:54:35 AM3/1/11
to circuits
On Mar 1, 12:45 am, James Mills <prolo...@shortcircuit.net.au> wrote:

> However: What is weberror, what is EvalException ?

See http://packages.python.org/WebCore/modules/thirdparty/weberror.html
for details, but basically weberror is a set of tools for handling
exceptions for web apps, and EvalException (part of weberror) provides
a web-based interactive debugging interface such that if an exception
is thrown in your app, it catches it and allows you to run python
commands in the browser for debugging. It used to be part of Paste
and was the default debugging tool for Pylons.

> The circuits.web.wsgi.Gateway component
> accepts as it's argument 2 things:
>  * a path to mount the WSGI application on
>  * the WSGI application callable
>
> Please see the tests/web for how this work.

I've looked at the tests, examples, source code, and have
experimented, but haven't had any success.

The class weberror.evalexception.EvalException __init__() requires an
"application" and allows many optional parameters. What do I pass as
the application? The class defines __call__(self, environ,
start_response).

Thanks.
Ron

James Mills

unread,
Mar 1, 2011, 2:36:58 AM3/1/11
to circuit...@googlegroups.com
On Tue, Mar 1, 2011 at 4:54 PM, NCRonB <ronbi...@gmail.com> wrote:
> The class weberror.evalexception.EvalException __init__() requires an
> "application" and allows many optional parameters.  What do I pass as
> the application?  The class defines __call__(self, environ,
> start_response).

If it defines a __call_(environ, start_response) ...

Then it _is_ a WSGI Application / Callable.

IN that case do this:

Gateway("/weberror", EvalException())

That will create the EvalException application
instance and mount it on the web path /weberror
(using the circuits.web server / framework).

It should then be accessible via:

http://localhost:8000/weberror (for example)

Hope this helps,

cheers
James

--
-- James Mills
--
-- "Problems are solved by method"

NCRonB

unread,
Mar 1, 2011, 7:16:22 PM3/1/11
to circuits
On Mar 1, 2:36 am, James Mills <prolo...@shortcircuit.net.au> wrote:

> On Tue, Mar 1, 2011 at 4:54 PM, NCRonB <ronbick...@gmail.com> wrote:
> > The class weberror.evalexception.EvalException __init__() requires an
> > "application" and allows many optional parameters.  What do I pass as
> > the application?

> Gateway("/weberror", EvalException())

I did the above (except with the app before the path), and I get the
following on startup:

TypeError: __init__() takes at least 2 arguments (1 given)

EvalException requires an application be passed to it. I now
understand that EvalException is middleware and expects to be wrapped
around another app to capture exceptions thrown by that app.

I tried the following:

app = Application() + Root()
(Server(8000) + Gateway(EvalException(app), "")).run()

While it appears to work as expected, circuits.web handles the
exceptions that Root() raises and I don't know how to make it pass
them back through to EvalException. How can I do that?

I did come across the following exception while messing with it:

File '/home/bickersfam/circuits/lib/python2.6/site-packages/
WebError-0.10.3-py2.6.egg/weberror/evalexception.py', line 424 in
detect_start_response
return start_response(status, headers, exc_info)
File '/home/bickersfam/circuits/lib/python2.6/site-packages/
circuits-1.5-py2.6.egg/circuits/web/wsgi.py', line 170 in
start_response
self._response.headers.add_header(*header)
File '/home/bickersfam/circuits/lib/python2.6/site-packages/
circuits-1.5-py2.6.egg/circuits/web/headers.py', line 272 in
add_header
self._headers.append((_name, "; ".join(parts)))
TypeError: sequence item 0: expected string, long found

That exception passed back to EvalException and I got a nice
interactive debugger in my browser and was able to see that
evalexception passed a header 'Content-Length'=71667L which isn't the
string circuits.web was expecting. This might be a problem in my own
controller; I'll have to look into that later, but the important thing
is that EvalException worked nicely for that exception.

James Mills

unread,
Mar 2, 2011, 5:21:25 AM3/2/11
to circuit...@googlegroups.com
On Wed, Mar 2, 2011 at 10:16 AM, NCRonB <ronbi...@gmail.com> wrote:
> EvalException requires an application be passed to it.  I now
> understand that EvalException is middleware and expects to be wrapped
> around another app to capture exceptions thrown by that app.
>
> I tried the following:
>
>  app = Application() + Root()
>  (Server(8000) + Gateway(EvalException(app), "")).run()
>
> While it appears to work as expected, circuits.web handles the
> exceptions that Root() raises and I don't know how to make it pass
> them back through to EvalException.  How can I do that?

You can try to listen to the web:httperror events and
re-raise the exception. That might work. I haven't tested this
(I'm asking you to) :)

Let me know... Otherwise I'll find the "right way" to do that...

> I did come across the following exception while messing with it:
>
> File '/home/bickersfam/circuits/lib/python2.6/site-packages/
> WebError-0.10.3-py2.6.egg/weberror/evalexception.py', line 424 in
> detect_start_response
>  return start_response(status, headers, exc_info)
> File '/home/bickersfam/circuits/lib/python2.6/site-packages/
> circuits-1.5-py2.6.egg/circuits/web/wsgi.py', line 170 in
> start_response
>  self._response.headers.add_header(*header)
> File '/home/bickersfam/circuits/lib/python2.6/site-packages/
> circuits-1.5-py2.6.egg/circuits/web/headers.py', line 272 in
> add_header
>  self._headers.append((_name, "; ".join(parts)))
> TypeError: sequence item 0: expected string, long found
>
> That exception passed back to EvalException and I got a nice
> interactive debugger in my browser and was able to see that
> evalexception passed a header 'Content-Length'=71667L which isn't the
> string circuits.web was expecting.  This might be a problem in my own
> controller; I'll have to look into that later, but the important thing
> is that EvalException worked nicely for that exception.

This might be a new bug you've discovered.

If you could do some "debugging" and let me know if
there's something I need to fix with circuits.web ?

Thanks,

NCRonB

unread,
Mar 2, 2011, 2:11:40 PM3/2/11
to circuits
On Mar 2, 5:21 am, James Mills <prolo...@shortcircuit.net.au> wrote:

> > While it appears to work as expected, circuits.web handles the
> > exceptions that Root() raises and I don't know how to make it pass
> > them back through to EvalException.  How can I do that?
>
> You can try to listen to the web:httperror events and
> re-raise the exception. That might work. I haven't tested this
> (I'm asking you to) :)

I created a handler to listen to those events and it was executed, but
the exceptions did not pass on to EvalException.

> This might be a new bug you've discovered.
>
> If you could do some "debugging" and let me know if
> there's something I need to fix with circuits.web ?

As best I can figure out, the evalexception middleware passed a header
('Content-Length', 29297L) to wsgi.Gateway.start_response(), but
circuits is expecting all header values to be string or None types.
Beyond that, I got lost in what's going on.

James Mills

unread,
Mar 2, 2011, 8:31:21 PM3/2/11
to circuit...@googlegroups.com
On Thu, Mar 3, 2011 at 5:11 AM, NCRonB <ronbi...@gmail.com> wrote:
> I created a handler to listen to those events and it was executed, but
> the exceptions did not pass on to EvalException.

Hmmm unfortunately due to the architecture of circuits
I'm not exactly sure how to accomplish what you want
and what the evalexception middleware needs.

The basic problem is this...

If you have a look at circuits/core/manager.py
at about L445 -- the __handleEvent method

You'll see that any and every exception that may
occur in a circuits application is trapped, cleaned up
and an appropriate Event fired for it (which the HTTP
protocol Component in circuits.web listens for).

I'm not sure how to pass the exception back up the chain
unless I were to add a setting into the Manager (the base
of all components) that told it to re-raise exceptions so that
things like evalexcception could then trap them.

I wonder though if it might be possible to somehow listen
to the web:httperror event and instead weave in the
evalexception middleware right then. Meaning that you
do a return evalexception() -- where evalexception() returns
a valid response (somehow) -- You might have to do some
integration of some circuits.web.wsgi.Gateway with this new
event handler (in your app).

> As best I can figure out, the evalexception middleware passed a header
> ('Content-Length', 29297L) to wsgi.Gateway.start_response(), but
> circuits is expecting all header values to be string or None types.
> Beyond that, I got lost in what's going on.

Cool. Thank you. I'll write a test for this and fix taht bug.

Justin Giorgi

unread,
Mar 3, 2011, 12:36:52 AM3/3/11
to circuit...@googlegroups.com
James,

You could modify your error trapping to prevent errors raised within error handlers from being trapped. I'm not sure how feasible this would be but it would make it easy to wrap any number of exception handling systems.

Probably a dumb idea but I thought I would throw it out there.

--
You received this message because you are subscribed to the Google Groups "circuits" group.
To post to this group, send email to circuit...@googlegroups.com.
To unsubscribe from this group, send email to circuits-user...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/circuits-users?hl=en.




--
Sincerely,
Justin Giorgi
Kamili Hosting Services - Systems Architect

P.O. Box 5115
Klamath Falls, OR 97601
(541)205-1684
justin...@gmail.com

James Mills

unread,
Mar 3, 2011, 1:51:43 AM3/3/11
to circuit...@googlegroups.com
On Thu, Mar 3, 2011 at 3:36 PM, Justin Giorgi <justin...@gmail.com> wrote:
> You could modify your error trapping to prevent errors raised within error
> handlers from being trapped. I'm not sure how feasible this would be but it
> would make it easy to wrap any number of exception handling systems.
> Probably a dumb idea but I thought I would throw it out there.

I'm not entirely sure what to do here...

This (to me) is a special case - where you want to
pass exceptions out to a wsgi callable (middleware).

Any other ideas ?

NCRonB

unread,
Mar 3, 2011, 2:58:28 AM3/3/11
to circuits
On Mar 2, 8:31 pm, James Mills <prolo...@shortcircuit.net.au> wrote:

> Hmmm unfortunately due to the architecture of circuits
> I'm not exactly sure how to accomplish what you want
> and what the evalexception middleware needs.

I thought that might be the case the more I looked through the code.

> I wonder though if it might be possible to somehow listen
> to the web:httperror event and instead weave in the
> evalexception middleware right then. Meaning that you
> do a return evalexception() -- where evalexception() returns
> a valid response (somehow) -- You might have to do some
> integration of some circuits.web.wsgi.Gateway with this new
> event handler (in your app).

I'm sure there's some way to integrate it, though perhaps not without
significant coding that I'm not prepared to do. I can do without it
for now, but I'm interested in seeing what, if any, solution there is
in a future release.

Thanks for your time!

James Mills

unread,
Mar 3, 2011, 4:00:57 AM3/3/11
to circuit...@googlegroups.com
On Thu, Mar 3, 2011 at 5:58 PM, NCRonB <ronbi...@gmail.com> wrote:
> I'm sure there's some way to integrate it, though perhaps not without
> significant coding that I'm not prepared to do.  I can do without it
> for now, but I'm interested in seeing what, if any, solution there is
> in a future release.

Have you seen circuits.web.apps ?

It contains a webconsole (very similar kind of thing).

I'll have a think about this in general some more...

NCRonB

unread,
Mar 3, 2011, 1:25:48 PM3/3/11
to circuits
On Mar 3, 4:00 am, James Mills <prolo...@shortcircuit.net.au> wrote:

> Have you seen circuits.web.apps ?
>
> It contains a webconsole (very similar kind of thing).

I did look at that briefly. It looked interesting, but since I was
focused on exception catching, I didn't dig too deep.
Reply all
Reply to author
Forward
0 new messages