gh-104522: Change message returned by subprocess when cwd option is not the cause #104851
+18
−4
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Refers to #104522
Summary of change:
subprocess._execute_child
would raise an exception referencingcwd
as the cause of the issue even if this not the case.So in the sample code:
subprocess
will put the blame oncwd
but raise the correct exception. This can be misleading to the user as to what the correct cause is.Current state of this PR,:
The exception type is checked by instantiating an error object store in
child_exception_type
which is OSError, but when supplied the errno and any string can be tested withisinstance
to check forFileNotFoundError
andNotADirectoryError
, these exceptions imply thatcwd
is most certainly the error as at this point as the subprocess was inpreexec
. Although if other errors are raise in this context the errno and message are still raised but contents ofcwd
will not be passed the exception.