Skip to content

gh-104522: Change message returned by subprocess when cwd option is not the cause #104851

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

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 17 additions & 4 deletions Lib/subprocess.py
Original file line number Diff line number Diff line change
Expand Up @@ -1946,14 +1946,27 @@ def _execute_child(self, args, executable, preexec_fn, close_fds,
errno_num = int(hex_errno, 16)
child_exec_never_called = (err_msg == "noexec")
if child_exec_never_called:
err_msg = ""
# The error must be from chdir(cwd).
err_filename = cwd
# creates a temporary error to be able to check for FileNotFoundError.
# This is done because if it is a FileNotFoundError the cwd option
# is the issue, otherwise we should just return the error without setting
# a filename. The error message needs to be supplied so passing an empty string
# is required.
temp_error = child_exception_type(errno_num, "")
if isinstance(temp_error, FileNotFoundError) \
or isinstance(temp_error, NotADirectoryError):
err_msg = ""
# The error must be from chdir(cwd).
err_filename = cwd
else:
err_filename = None
else:
err_filename = orig_executable
if errno_num != 0:
err_msg = os.strerror(errno_num)
raise child_exception_type(errno_num, err_msg, err_filename)
if err_filename is not None:
raise child_exception_type(errno_num, err_msg, err_filename)
else:
raise child_exception_type(errno_num, err_msg)
raise child_exception_type(err_msg)


Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Changed misleading error message for running a subprocess.