[Python-ideas] Structured Error Output

Bryce Boe bboe at cs.ucsb.edu
Thu Apr 26 00:06:16 CEST 2012


>> I looked through the man page for python's interpreter and appears
>> that there is no way to properly distinguish between error messages
>> output to stderr by the interpreter and output produced the by a
>> user-program to stderr.
>
>
> That should be a false distinction. User programs should only print error
> messages to stderr. Some modify error messages before they get printed. Some
> raise exceptions themselves with messages. The interpreter makes makes no
> distinction between user code, 3rd party code, and stdlib code.

Perhaps I wasn't very clear. I want to write a tool to collect error
messages when I run a program. Ideally the tool should be agnostic to
what language is used and should be able to identify syntax errors,
parser errors, and runtime errors. While I can parse both the stdout
and stderr streams to find this information, from what I can tell
there is no way to distinguish between a real syntax error (output to
stderr):

  File "./test.py", line 5
    class
        ^
SyntaxError: invalid syntax

and a program that outputs that exact output to stderr and exits with status 1.

This "channel" sharing of control (error messages) and data is a
problem that affects more than just the python interpreter. I am
hoping to start with python and provide a way to separate the control
and data information so I can be certain that output on the "control"
file descriptor is guaranteed to be generated by the interpreter.

> Exception instances have a .__traceback__ instance that is used to print the default traceback message

I am aware I can obtain this information and output it however I want
from my own program (less syntax errors), however, the goal is to run
third party code and provide a more detailed error report.

-Bryce



More information about the Python-ideas mailing list