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

Discussion in 'Python' started by Kenneth McDonald, Jun 15, 2004.

  1. 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
    Kenneth McDonald, Jun 15, 2004
    #1
    1. Advertising

  2. Kenneth McDonald

    Peter Hansen Guest

    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
    Peter Hansen, Jun 16, 2004
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    9
    Views:
    80,606
    Naga Syamala A
    Feb 17, 2012
  2. Praveen Bengeri
    Replies:
    1
    Views:
    295
    Tom Kaminski [MVP]
    Apr 19, 2004
  3. Stuart Palmer

    Non friendly error messages

    Stuart Palmer, Aug 11, 2004, in forum: ASP General
    Replies:
    2
    Views:
    146
    Stuart Palmer
    Aug 13, 2004
  4. Sam
    Replies:
    1
    Views:
    156
    A. Sinan Unur
    Feb 20, 2007
  5. Hazard Seventyfour

    The best, friendly and easy use Python Editor.

    Hazard Seventyfour, Jan 24, 2013, in forum: Python
    Replies:
    33
    Views:
    309
    Wayne Werner
    Jan 31, 2013
Loading...

Share This Page