classification
Title: Improve error message of subprocess when cannot open
Type: enhancement Stage:
Components: Extension Modules Versions: Python 3.2
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: LambertDW, amaury.forgeotdarc, benjamin.peterson, brian.curtin, endian, mmokrejs, r.david.murray, terry.reedy
Priority: normal Keywords: easy, patch

Created on 2009-01-12 16:26 by mmokrejs, last changed 2010-11-20 18:29 by brian.curtin. This issue is now closed.

Files
File name Uploaded Description Edit
issue4925.diff endian, 2010-11-20 17:57 now with errno.ENOENT instead of 2
Messages (8)
msg79684 - (view) Author: Martin Mokrejs (mmokrejs) Date: 2009-01-12 16:26
I think the following error output unsatisfactory as it does not give me
any hint what file was not found:

$ fetch_quals.py blah.txt 
Traceback (most recent call last):
  File "/home/mmokrejs/bin/fetch_quals.py", line 15, in <module>
    _p1 = subprocess.Popen(['query_tracedb', 'retrieve', 'quality',
_id], stdin=subprocess.PIPE, stdout=subprocess.PIPE)
  File "/usr/lib/python2.5/subprocess.py", line 594, in __init__
    errread, errwrite)
  File "/usr/lib/python2.5/subprocess.py", line 1091, in _execute_child
    raise child_exception
OSError: [Errno 2] No such file or directory
$

I know now that I had to specify full path tot he binary or include
shell=True argument but anyway, please improve the error message.
msg79685 - (view) Author: David W. Lambert (LambertDW) Date: 2009-01-12 17:17
Related, but outside python realm, this error likewise confuses:

$ cat <<EOF > s.sh
#! invalid path
echo hi
EOF
$ ./s.sh 
zsh: no such file or directory: ./s.sh
msg79697 - (view) Author: David W. Lambert (LambertDW) Date: 2009-01-12 19:39
(Actual command stream includes chmod +x ./s.sh)
msg108644 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2010-06-25 23:08
Improved error messages are feature requests because 1) there is no particular guarantee in the doc and 2) changes can break existing code, so should only happen in an new x.y version.

When reporting behavior, it is helpful to give *minimal* code that will reproduce, either in the message if small, or attached. For example, with 3.1.2 on WixXP

>>> import subprocess
>>> subprocess.Popen("xyz")
gives
WindowsError: [Error 2] The system cannot find the file specified

Although in this case the literal name is in the traceback, it is not always. So I am leaving this open. Given that

>>> open('xyx')
gives the more helpful
IOError: [Errno 2] No such file or directory: 'xyx'

it seems it might be possible by using the io code.
msg108895 - (view) Author: Amaury Forgeot d'Arc (amaury.forgeotdarc) * (Python committer) Date: 2010-06-29 07:26
in PC/_subprocess.c, it should be enough to use PyErr_SetFromWindowsErrWithFilename() instead of PyErr_SetFromWindowsErr()
msg121678 - (view) Author: Andrew Schaaf (endian) Date: 2010-11-20 16:32
I'm working this for platforms that use OSError. #pythonbugday2010 #myfirstpatch
msg121700 - (view) Author: Benjamin Peterson (benjamin.peterson) * (Python committer) Date: 2010-11-20 18:08
r86593
msg121701 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2010-11-20 18:15
Note that Benjamin's commit only addresses the posix side.  Amaury, do you want to fix the windows side?
History
Date User Action Args
2010-12-21 12:24:23eric.smithlinkissue10715 superseder
2010-11-20 18:29:36brian.curtinsetnosy: + brian.curtin
2010-11-20 18:15:52r.david.murraysetnosy: + r.david.murray
messages: + msg121701
2010-11-20 18:08:24benjamin.petersonsetstatus: open -> closed

nosy: + benjamin.peterson
messages: + msg121700

resolution: fixed
2010-11-20 18:00:21endiansetfiles: - issue4925.diff
2010-11-20 17:57:49endiansetfiles: + issue4925.diff
2010-11-20 17:37:27endiansetfiles: + issue4925.diff
2010-11-20 16:51:58endiansetfiles: - issue4925.diff
2010-11-20 16:43:23endiansetfiles: + issue4925.diff
keywords: + patch
2010-11-20 16:32:05endiansetnosy: + endian
messages: + msg121678
2010-06-29 07:26:05amaury.forgeotdarcsetkeywords: + easy
nosy: + amaury.forgeotdarc
messages: + msg108895

2010-06-25 23:08:18terry.reedysetnosy: + terry.reedy
title: Improve error message of subprocess -> Improve error message of subprocess when cannot open
messages: + msg108644

versions: + Python 3.2, - Python 2.5
type: behavior -> enhancement
2009-01-12 19:39:09LambertDWsetmessages: + msg79697
2009-01-12 17:17:12LambertDWsetnosy: + LambertDW
messages: + msg79685
2009-01-12 16:26:57mmokrejscreate