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.
This PR maps
Errno::ENOEXEC
andWinError::ERROR_BAD_EXE_FORMAT
to a new exception class,File::BadExecutableError
, that is raised ifProcess.new
receives a file that has execute permissions but isn't really an executable file.WinError::ERROR_BAD_EXE_FORMAT
passes the file argument toLibC.FormatMessageW
. Fixes #12985. (The new exception class isn't technically necessary, I just think this is a good chance to capture this error in a platform-independent way.)Note that this doesn't happen naturally on POSIX systems, where
Process.new
is backed byLibC.execvp
; ifexecvp
failed because ofENOEXEC
, execution of the same file is attempted again viash
as though it is a shell script. Therefore, trying to execute a Windows executable on a non-WSL Linux produces:However, musl is known not to fall back to
sh
, in which caseFile::BadExecutableError
could still be caught. If we want to useLibC.execv
instead then we must replicate the$PATH
lookup ourselves when the file name does not include a slash character.This PR also maps
WinError::ERROR_ACCESS_DENIED
toFile::AccessDeniedError
. This happens whenProcess.new
receives a directory on Windows.