This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: runpy hides traceback for some exceptions
Type: behavior Stage:
Components: Interpreter Core Versions: Python 3.4
process
Status: closed Resolution: duplicate
Dependencies: Superseder: Traceback wrong on ImportError while executing a package
View: 14285
Assigned To: Nosy List: martin.panter, ncoghlan, sleepycal
Priority: normal Keywords:

Created on 2015-11-23 14:49 by sleepycal, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Messages (2)
msg255169 - (view) Author: Cal Leeming (sleepycal) Date: 2015-11-23 14:49
Originally posted here:
http://stackoverflow.com/q/33873243/1267398

The problem is caused by this line:

    # For -m switch, just display the exception
    info = str(exc)

Caused by the following commit in 2008;
https://mail.python.org/pipermail/python-checkins/2008-February/066256.html

The commit states;
"Try to make command line error messages from runpy easier to understand (and suppress traceback cruft from the implicitly invoked runpy machinery)"

However by suppressing the traceback it's now impossible to debug what caused the error when running with `runpy` without wrapping the entire `__init__.py` with your own try/except statement.

I'd like to propose either displaying the full traceback by default, or adding a CLI option to enable it at runtime. The fact that it only suppresses *some* tracebacks and not all is a flawed approach surely?

Thoughts?
msg255638 - (view) Author: Martin Panter (martin.panter) * (Python committer) Date: 2015-12-01 03:52
I think there are a couple of related bugs here, with open reports:

1. Issue 14285: runpy catches various exceptions including AttributeError, and incorrectly assumes this means you gave it a bad module or package name.

2. Issue 19771: runpy incorrectly interprets exceptions such as in (1) as meaning the package doesn’t have a __main__ submodule. But these exceptions can happen even if hello.__main__ exists. My patch there changes the error message to:

/home/proj/python/cpython/python: Error while finding spec for 'hello.__main__' (AttributeError: module 'random' has no attribute 'dsgjdgj')

3. Issue 16217: runpy should handle exceptions from user code by printing out the relevant traceback, rather than letting the Python interpreter print out all the internal runpy frames.

Marking this as a dupe of Issue 14285, but I think a proper solution to that would probably affect the other two as well.
History
Date User Action Args
2022-04-11 14:58:24adminsetgithub: 69894
2015-12-01 03:52:31martin.pantersetstatus: open -> closed

nosy: + martin.panter
messages: + msg255638

superseder: Traceback wrong on ImportError while executing a package
resolution: duplicate
2015-11-23 14:49:24sleepycalcreate