Any easy way to get more RE-friendly error messages from Python?

K

Kenneth McDonald

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
 
P

Peter Hansen

Kenneth said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,733
Messages
2,569,440
Members
44,831
Latest member
HealthSmartketoReviews

Latest Threads

Top