New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
incorrect path in subprocess.Popen() FileNotFoundError message #60318
Comments
The error message in the FileNotFoundError error raised by subprocess.Popen() displays the wrong path when the bad path is due to the executable argument rather than args. The message gives the path for args[0] rather than for the executable argument. For example, this-- import subprocess, sys
python_path = sys.executable
p = subprocess.Popen([python_path, "-c", "import sys; sys.exit(1)"])
p.wait()
p = subprocess.Popen([python_path, "-c", "import sys; sys.exit(1)"],
executable="foo")
p.wait() gives-- Traceback (most recent call last):
File "test-subprocess.py", line 6, in <module>
executable="foo")
File ".../Lib/subprocess.py", line 818, in __init__
restore_signals, start_new_session)
File ".../Lib/subprocess.py", line 1416, in _execute_child
raise child_exception_type(errno_num, err_msg)
FileNotFoundError: [Errno 2] No such file or directory: '.../python.exe' The path in the last line should read "foo" since '.../python.exe' is obviously found as evidenced from the previous Popen() invocation. |
2.7 is not affected because 2.7 makes no attempt to display the path: OSError: [Errno 2] No such file or directory |
It looks like the error is here: if issubclass(child_exception_type, OSError) and hex_errno:
errno_num = int(hex_errno, 16)
if errno_num != 0:
err_msg = os.strerror(errno_num)
if errno_num == errno.ENOENT:
err_msg += ': ' + repr(args[0])
raise child_exception_type(errno_num, err_msg)
raise child_exception_type(err_msg) http://hg.python.org/cpython/file/b40025e37bcd/Lib/subprocess.py#l1415 The "args[0]" should be "executable" when appropriate. |
Adding bpo-16115 as a dependency so that the more general case can be settled and committed before dealing with the current issue's more specific (and platform-specific) case. |
Attaching proposed tests. |
Maybe better to fix Windows behavior for unifying FileNotFoundError? |
I will be opening a separate issue to have the same behavior in a future version after this issue is closed. For existing releases, we don't want to break working code that could be relying on the difference. |
Sorry, I was confusing this issue with bpo-15533. Yes, I support adding the file path to the error message in the Windows implementation, though my preference would be for that to be addressed as part of a separate issue. |
I'm ok with your patch if it will be applied to 3.2 etc and after that new issue will fix Windows problem. |
By "patch" do you mean "test"? And by "works", do you mean fails or succeeds? :) I haven't prepared a patch yet, but I just started working on it. On my machine, I found that the test fails as is on 3.3 and 3.4, but on 3.2 it fails for a different reason: the FileNotFoundError needs to be switched to OSError (which was to be expected). |
replacing repr(args[0]) with repr(executable) in the identified python should be sufficient for this bug as originally reported. BUT it goes deeper: I just ran into this error in a different case. It also happens when cwd is passed and the chdir(cwd) fails in the child process. args[0] is reported as not found rather than cwd in the error message. I have a test and fix for that. I'll take care of both. |
Yes, almost. The executable variable is a bytes object so it needs to be fsdecoded first.
Let me at least upload what I already prepared. You can add to it or modify it as you see fit. |
New changeset e938fa6be509 by Gregory P. Smith in branch '3.2': New changeset ee30d7ef70be by Gregory P. Smith in branch '3.3': |
New changeset 543bb0e0afb9 by Gregory P. Smith in branch 'default': |
I'm keeping this open until I backport this to subprocess32 for use on Python 2. |
I made some comments on the changes as committed here: http://mail.python.org/pipermail/python-dev/2012-October/122125.html """ I would also check for FileNotFoundError instead of OSError in the 3.3 |
I created bpo-16185 to include the path in the messages of the corresponding errors on Windows. |
fyi - I agree with your comments about the test and assertRaises. This code is old, there's a lot that could be improved in there. I chose to maintain a style equivalent to the existing surrounding code. Feel free to clean that up. |
I backported the fix to this in the subprocess32 3.2.5rc1 release I made a week or two ago. |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: