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.
Created on 2014年10月02日 00:49 by charpov, last changed 2022年04月11日 14:58 by admin. This issue is now closed.
| Files | ||||
|---|---|---|---|---|
| File name | Uploaded | Description | Edit | |
| bug.py | charpov, 2014年10月02日 00:49 | |||
| 22536-subprocess-exception-filename.patch | travis.thieman, 2014年11月15日 21:42 | review | ||
| 22536-subprocess-exception-filename-2.patch | travis.thieman, 2014年11月30日 03:03 | review | ||
| Pull Requests | |||
|---|---|---|---|
| URL | Status | Linked | Edit |
| PR 3194 | merged | gregory.p.smith, 2017年08月23日 20:55 | |
| PR 3202 | merged | gregory.p.smith, 2017年08月25日 00:12 | |
| PR 3305 | merged | gregory.p.smith, 2017年09月04日 20:55 | |
| Messages (13) | |||
|---|---|---|---|
| msg228147 - (view) | Author: Michel Charpentier (charpov) | Date: 2014年10月02日 00:49 | |
FileNotFoundError should contain a 'filename' information, as per its specification. It's 'None' after a failure to execute a subprocess. |
|||
| msg231221 - (view) | Author: Travis Thieman (travis.thieman) * | Date: 2014年11月15日 21:42 | |
The attached patch includes the first element in args in _execute_child to the OSError exception subclass. This correctly populates the 'filename' field on the resulting exception. A test is also included that fails without the patch. |
|||
| msg231293 - (view) | Author: Akira Li (akira) * | Date: 2014年11月17日 20:55 | |
I can confirm that without the patch the filename attribute is None
despite being mentioned in strerror.
Travis, you should use `orig_executable` instead of `args[0]` to cover:
subprocess.call("exit 0", shell=True, executable='/nonexistent bash')
case.
And use `cwd` if `child_exec_never_called`, to be consistent with the error message (see if/else statements above the raise statement).
It seems appropriate to set filename even if errno is not ENOENT
but to be conservative, you could provide filename iff `err_msg` is also changed i.e., iff errno is ENOENT.
|
|||
| msg231297 - (view) | Author: Akira Li (akira) * | Date: 2014年11月17日 21:28 | |
If the_oserror.filename is not None then str(the_oserror) appends the filename twice: [Errno 2] No such file or directory: 'nonexistent': 'nonexistent' You could remove `err_msg += ':' ...` statements to avoid the repeatition. It may break the code that uses strerror attribute. But exception error messages are explicitly excluded from backward compatibility considirations therefore it might be ok to break it here. I can't find the reference so it should probably be resolved as a new issue (independent from providing the filename attribute value). |
|||
| msg231392 - (view) | Author: STINNER Victor (vstinner) * (Python committer) | Date: 2014年11月19日 16:39 | |
You should only add the filename if the error if a FileNotFound exception, not for any OSError, and only if exec() was called. It looks like the variable child_exec_never_called indicates if exec() was called. |
|||
| msg231400 - (view) | Author: Akira Li (akira) * | Date: 2014年11月19日 22:38 | |
It would be inconsitent to provide filename only if exec is called e.g.:
>>> import subprocess
subprocess.call("not used", cwd="nonexistent")
FileNotFoundError: [Errno 2] No such file or directory: 'nonexistent'
The error message shows the filename (cwd) despite exec not being
called therefore it would be logical to provide non-None `filename`
attribute here too.
If we ignore the backward compatibility issue I've mentioned in msg231297
then the current code:
if errno_num == errno.ENOENT:
if child_exec_never_called:
# The error must be from chdir(cwd).
err_msg += ': ' + repr(cwd)
else:
err_msg += ': ' + repr(orig_executable)
raise child_exception_type(errno_num, err_msg)
could be replaced with:
if errno_num == errno.ENOENT:
if child_exec_never_called:
# The error must be from chdir(cwd).
filename = cwd
else:
filename = orig_executable
raise child_exception_type(errno_num, err_msg, filename)
raise child_exception_type(errno_num, err_msg)
[1] https://hg.python.org/cpython/file/23ab1197df0b/Lib/subprocess.py#l1443
|
|||
| msg231414 - (view) | Author: STINNER Victor (vstinner) * (Python committer) | Date: 2014年11月20日 06:38 | |
I wnated to say that args[0] is not the right filename if exec() was not called. Yes, there is also cwd for example. The logic to choose the filename should be done in the child. |
|||
| msg231881 - (view) | Author: Travis Thieman (travis.thieman) * | Date: 2014年11月30日 03:03 | |
Thank you all for the helpful comments. A revised attempt is attached as -2.patch, with improved behavior around using cwd if the child is never called and orig_executable if it is. I opted not to fix the issue with the redundancy in the error message as I agree that should be handled as a separate issue. |
|||
| msg300751 - (view) | Author: Christian H (Christian H) | Date: 2017年08月23日 13:33 | |
I was also bitten by this bug, and would like to see it merged. The patch 22536-subprocess-exception-filename-2.patch looks fine to me. |
|||
| msg300808 - (view) | Author: Gregory P. Smith (gregory.p.smith) * (Python committer) | Date: 2017年08月24日 21:58 | |
New changeset 8621bb5d93239316f97281826461b85072ff6db7 by Gregory P. Smith in branch 'master': bpo-22536: Set the filename in FileNotFoundError. (#3194) https://github.com/python/cpython/commit/8621bb5d93239316f97281826461b85072ff6db7 |
|||
| msg300814 - (view) | Author: STINNER Victor (vstinner) * (Python committer) | Date: 2017年08月24日 23:37 | |
Your change makes test_subprocess f1iling on Windows. Example: http://buildbot.python.org/all/builders/AMD64%20Windows7%20SP1%203.x/builds/891/steps/test/logs/stdio |
|||
| msg300815 - (view) | Author: Gregory P. Smith (gregory.p.smith) * (Python committer) | Date: 2017年08月25日 00:06 | |
right, the test needs to be excluded there. fixing... (bummer windows wasn't in the CI) |
|||
| msg301266 - (view) | Author: Gregory P. Smith (gregory.p.smith) * (Python committer) | Date: 2017年09月04日 21:23 | |
New changeset 1dba3789e335f06e3b01cdc84070f2e828c9b861 by Gregory P. Smith in branch '3.6': bpo-22536 [3.6] Set filename in FileNotFoundError (#3305) https://github.com/python/cpython/commit/1dba3789e335f06e3b01cdc84070f2e828c9b861 |
|||
| History | |||
|---|---|---|---|
| Date | User | Action | Args |
| 2022年04月11日 14:58:08 | admin | set | github: 66726 |
| 2017年09月06日 20:40:35 | gregory.p.smith | set | status: open -> closed stage: patch review -> resolved resolution: fixed versions: + Python 3.6, Python 3.7, - Python 3.4, Python 3.5 |
| 2017年09月04日 21:23:25 | gregory.p.smith | set | messages: + msg301266 |
| 2017年09月04日 20:55:33 | gregory.p.smith | set | pull_requests: + pull_request3335 |
| 2017年08月25日 00:12:42 | gregory.p.smith | set | pull_requests: + pull_request3241 |
| 2017年08月25日 00:06:48 | gregory.p.smith | set | messages: + msg300815 |
| 2017年08月24日 23:37:19 | vstinner | set | messages: + msg300814 |
| 2017年08月24日 21:58:27 | gregory.p.smith | set | messages: + msg300808 |
| 2017年08月23日 21:11:32 | gregory.p.smith | set | assignee: gregory.p.smith |
| 2017年08月23日 20:55:49 | gregory.p.smith | set | pull_requests: + pull_request3233 |
| 2017年08月23日 13:33:42 | Christian H | set | nosy:
+ Christian H messages: + msg300751 |
| 2014年11月30日 03:03:35 | travis.thieman | set | files:
+ 22536-subprocess-exception-filename-2.patch messages: + msg231881 |
| 2014年11月20日 06:38:51 | vstinner | set | messages: + msg231414 |
| 2014年11月19日 22:38:01 | akira | set | messages: + msg231400 |
| 2014年11月19日 16:39:25 | vstinner | set | nosy:
+ vstinner messages: + msg231392 |
| 2014年11月17日 21:28:04 | akira | set | messages: + msg231297 |
| 2014年11月17日 20:55:23 | akira | set | nosy:
+ akira messages: + msg231293 |
| 2014年11月16日 05:50:11 | berker.peksag | set | nosy:
+ berker.peksag stage: patch review versions: + Python 3.4 |
| 2014年11月15日 21:42:45 | travis.thieman | set | files:
+ 22536-subprocess-exception-filename.patch nosy: + travis.thieman messages: + msg231221 keywords: + patch |
| 2014年10月03日 16:20:17 | tshepang | set | nosy:
+ tshepang |
| 2014年10月02日 06:13:11 | ned.deily | set | nosy:
+ gregory.p.smith title: Missing filename in FileNotFoundError -> subprocess should include filename in FileNotFoundError exception assignee: ronaldoussoren -> (no value) versions: + Python 3.5, - Python 3.4 components: + Library (Lib), - Interpreter Core, macOS |
| 2014年10月02日 00:49:37 | charpov | create | |