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: Scripts invoked by -m should trim exceptions
Type: enhancement Stage:
Components: Library (Lib) Versions:
process
Status: closed Resolution: rejected
Dependencies: Superseder:
Assigned To: ncoghlan Nosy List: gvanrossum, ncoghlan, tcdelaney, tim.peters
Priority: normal Keywords:

Created on 2006-04-01 00:23 by tcdelaney, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Messages (7)
msg54767 - (view) Author: Tim Delaney (tcdelaney) Date: 2006-04-01 00:23
Currently in 2.5, an exception thrown from a script invoked by -m (runpy.run_module) will dump an exception like:

Traceback (most recent call last):
  File "D:\Development\Python25\Lib\runpy.py", line 418, in run_module
    filename, loader, alter_sys)
  File "D:\Development\Python25\Lib\runpy.py", line 386, in _run_module_code
    mod_name, mod_fname, mod_loader)
  File "D:\Development\Python25\Lib\runpy.py", line 366, in _run_code
    exec code in run_globals
  File "D:\Development\modules\test25.py", line 53, in <module>
    raise GeneratorExit('body')
GeneratorExit: body

This should probably be trimmed to:

Traceback (most recent call last):
  File "test25.py", line 53, in <module>
    raise GeneratorExit('body')
GeneratorExit: body

to match when a script is invoked by filename.
msg54768 - (view) Author: Guido van Rossum (gvanrossum) * (Python committer) Date: 2006-04-06 00:45
Logged In: YES 
user_id=6380

I'm not so sure. Who looks at the top of the traceback
anyway? And it might hide clues about problems caused by
runpy.py.
msg54769 - (view) Author: Nick Coghlan (ncoghlan) * (Python committer) Date: 2006-04-07 11:12
Logged In: YES 
user_id=1038590

I'd forgotten about SF's current "no email when assigned a
bug" feature. . .

I'm inclined to agree with Guido that it could be tricky to
get rid of these without also masking legitimate traceback
info for import errors (e.g. if the PEP 302 emulation
machinery blows up rather than returning None the way it is
meant to when it can't find a loader for the module).

OTOH, I don't like the current output for an import errror,
either:

C:\>C:\python25\python.exe -m junk
Traceback (most recent call last):
  File "C:\Python25\Lib\runpy.py", line 410, in run_module
    raise ImportError("No module named " + mod_name)
ImportError: No module named junk

So I'll look into it - if it is suspected that runpy is at
fault for a problem with running a script, then there's two
easy ways to get the full traceback:

C:\>C:\python25\python.exe -m runpy junk

C:\>C:\python25\python.exe C:\Python25\Lib\runpy junk
msg54770 - (view) Author: Nick Coghlan (ncoghlan) * (Python committer) Date: 2006-04-08 17:28
Logged In: YES 
user_id=1038590

I can fix it so that the runpy module lines are only masked
out when the module is invoked implicitly via the -m switch
by giving the C code a private entry point
(_run_module_as_main) that catches exceptions and prints the
filtered traceback before doing sys.exit(-1).

I'll make sure to add some tests to test_cmd_line to verify
the updated behaviour.
msg54771 - (view) Author: Tim Peters (tim.peters) * (Python committer) Date: 2006-04-08 20:23
Logged In: YES 
user_id=31435

I see no reason to bother with this -- it adds complexity,
and I don't see any real benefit.  What's bad about having
runpy show up in the traceback, given that code in runpy.py
actually _is_ in the call stack?  Why try to hide the truth
of it?
msg54772 - (view) Author: Guido van Rossum (gvanrossum) * (Python committer) Date: 2006-04-08 22:16
Logged In: YES 
user_id=6380

I'm with Tim. Please close w/o action.
msg54773 - (view) Author: Nick Coghlan (ncoghlan) * (Python committer) Date: 2006-04-09 02:44
Logged In: YES 
user_id=1038590

Done.
History
Date User Action Args
2022-04-11 14:56:16adminsetgithub: 43136
2006-04-01 00:23:23tcdelaneycreate