Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Python (http://www.velocityreviews.com/forums/f43-python.html)
-   -   Any easy way to get more RE-friendly error messages from Python? (http://www.velocityreviews.com/forums/t332161-any-easy-way-to-get-more-re-friendly-error-messages-from-python.html)

Kenneth McDonald 06-15-2004 10:31 PM

Any easy way to get more RE-friendly error messages from Python?
 
I'm setting myself up to use Python with jEdit (after trying
jed, VIM, others...urggh.) One small problem I'm having is
that while jEdit has a nice plugin called Console which can
be set up to run python scripts, and parse the result for
errors which can then be used to put the editing cursor
directly on the offending line, it doesn't play so well with
the multiline error messages that Python generates. (Actually,
I've never liked them a lot myself :-) ) The easiest way
to deal with this is probably to hack Python to put out
its error messages in a different format: I can think of
a couple of approaches, but they seem a little kludgey,
so I thought I'd solicit suggestions from the group.

So instead of error output that looks like this:

Traceback (most recent call last):
File "__init__.py", line 75, in ?
DNOTE('''This documentation was writting using the 'doco' module.'''),
NameError: name 'DNOTE' is not defined

I'd prefer something like:

PyError:__init__.py:75:NameError: name 'DNOTE' is not defined

(with, obviously, one such line for each element of the traceback.)


The thoughts that come to me first are:

1) Write some sort of wrapper to python.
2) Find and change an internal python hook.

I'm wondering what other ways of approaching this might
be suggested--both of the above have certain elements
I dislike.


Thanks,
Ken

Peter Hansen 06-15-2004 11:23 PM

Re: Any easy way to get more RE-friendly error messages from Python?
 
Kenneth McDonald wrote:

> Traceback (most recent call last):
> File "__init__.py", line 75, in ?
> DNOTE('''This documentation was writting using the 'doco' module.'''),
> NameError: name 'DNOTE' is not defined
>
> I'd prefer something like:
> PyError:__init__.py:75:NameError: name 'DNOTE' is not defined
>
> The thoughts that come to me first are:
> 2) Find and change an internal python hook.


sys.excepthook() is your friend here. See the module docs
for 'sys'. You could install it "globally" using a sitecustomize.py
file, most likely. (Check the site.py docs or source for more on that.)

Also check the source for traceback.py and see how it
formats stuff now. You can easily write your own formatter
that does things differently.

You might also check the source for Zope (or was it Twisted?
sorry, can't recall... maybe it was both!) which has a one-line
exception formatter somewhere, for log files, as I recall.

-Peter


All times are GMT. The time now is 03:01 AM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.