[issue43113] os.posix_spawn errors with wrong information when shebang points to not-existing file

2021-02-11 Thread Miro Hrončok
Miro Hrončok added the comment: At the very least, it's worth documenting in all places that can give you the exception, such as subprocess etc. Whether it's worth to try to fix the exception message I don't really know. Confused users on one side, fragile complex heuristic on the other.

[issue43113] os.posix_spawn errors with wrong information when shebang points to not-existing file

2021-02-10 Thread STINNER Victor
STINNER Victor added the comment: > Note that ENOENT is ambiguous, but the exception message is very specific > about what file is not found. And it is not always correct. If you want to be extra nice, you can try to check if the file exists. If it exists, add a message about the shebang.

[issue43113] os.posix_spawn errors with wrong information when shebang points to not-existing file

2021-02-10 Thread Alexey Izbyshev
Alexey Izbyshev added the comment: I generally agree, but getting a good, short error message seems to be the hard part here. I previously complained[1] about the following proposal by @hroncok: FileNotFoundError: [Errno 2] No such file or directory: Either './demo' or the interpreter of

[issue43113] os.posix_spawn errors with wrong information when shebang points to not-existing file

2021-02-10 Thread Eric V. Smith
Eric V. Smith added the comment: I agree with @hroncok, and maybe we could tweak the message to say FileNotFoundError: [Errno 2] No such file or directory: while executing './demo'. Maybe bad shebang, or missing file? Or something to that effect. I realize that listing all possible error

[issue43113] os.posix_spawn errors with wrong information when shebang points to not-existing file

2021-02-10 Thread Miro Hrončok
Miro Hrončok added the comment: Note that ENOENT is ambiguous, but the exception message is very specific about what file is not found. And it is not always correct. -- ___ Python tracker

[issue43113] os.posix_spawn errors with wrong information when shebang points to not-existing file

2021-02-10 Thread Alexey Izbyshev
Alexey Izbyshev added the comment: How do you propose to approach documentation of such behavior? The underlying cause is the ambiguity of ENOENT error code from execve() returned by the kernel, so it applies to all places where Python can call execve(), including os.posixspawn(),

[issue43113] os.posix_spawn errors with wrong information when shebang points to not-existing file

2021-02-10 Thread Tomas Orsava
Tomas Orsava added the comment: I agree that at least documenting the behaviour is a good idea. This bug has seriously confused our QE person with years of experience, and then me when debugging with him. Chances are it's going to confuse somebody else too. --

[issue43113] os.posix_spawn errors with wrong information when shebang points to not-existing file

2021-02-04 Thread Gregory P. Smith
Gregory P. Smith added the comment: That bash produces a nicer error message is because bash happens to implement its own special logic to try and figure out why an exec failed with an error other than ENOEXEC. The OS kernel & libc do not give it that information, there is no such errno.

[issue43113] os.posix_spawn errors with wrong information when shebang points to not-existing file

2021-02-04 Thread Eric V. Smith
Eric V. Smith added the comment: I suggest making no change here, except maybe documenting it somewhere. Removing the filename would make this problem even harder to diagnose. And adding additional code to an error condition just increases the chance of something failing. The error

[issue43113] os.posix_spawn errors with wrong information when shebang points to not-existing file

2021-02-03 Thread Alexey Izbyshev
Alexey Izbyshev added the comment: > IMO the fix is simple: only create OSError from the errno, never pass a > filename. This will remove a normally helpful piece of the error message in exchange to being marginally less confusing in a rare case of non-existing interpreter (the user will

[issue43113] os.posix_spawn errors with wrong information when shebang points to not-existing file

2021-02-03 Thread STINNER Victor
STINNER Victor added the comment: IMO the fix is simple: only create OSError from the errno, never pass a filename. posix_spawn() is really complex function which can fail in many different ways. Only in some very specific cases the filename is correct. """ ERRORS The posix_spawn()

[issue43113] os.posix_spawn errors with wrong information when shebang points to not-existing file

2021-02-03 Thread Alexey Izbyshev
Alexey Izbyshev added the comment: > FileNotFoundError: [Errno 2] No such file or directory: Either './demo' or > the interpreter of './demo' not found. This doesn't sound good to me because a very probable and a very improbable reasons are combined together without any distinction. Another

[issue43113] os.posix_spawn errors with wrong information when shebang points to not-existing file

2021-02-03 Thread Miro Hrončok
Miro Hrončok added the comment: That was "ideal" error message. If we don't have all the information, we cannot have the ideal error message. But we need to adapt the default error message to not be misleading. What about: FileNotFoundError: [Errno 2] No such file or directory: Either

[issue43113] os.posix_spawn errors with wrong information when shebang points to not-existing file

2021-02-03 Thread Alexey Izbyshev
Alexey Izbyshev added the comment: > Ideally, the error would say: > FileNotFoundError: ./demo: /usr/bin/hugo: bad interpreter: No such file or > directory The kernel simply returns ENOENT on an attempt to execve() a file with non-existing hash-bang interpreter. The same occurs on an

[issue43113] os.posix_spawn errors with wrong information when shebang points to not-existing file

2021-02-03 Thread STINNER Victor
STINNER Victor added the comment: > FileNotFoundError: ./demo: /usr/bin/hugo: bad interpreter: No such file or > directory Python has no knowledge of executable formats, shell or anything. It only calls posix_spawn() and raises an OSError on error. --

[issue43113] os.posix_spawn errors with wrong information when shebang points to not-existing file

2021-02-03 Thread Miro Hrončok
Miro Hrončok added the comment: Ideally, the error would say: FileNotFoundError: ./demo: /usr/bin/hugo: bad interpreter: No such file or directory -- ___ Python tracker ___

[issue43113] os.posix_spawn errors with wrong information when shebang points to not-existing file

2021-02-03 Thread STINNER Victor
STINNER Victor added the comment: > FileNotFoundError: [Errno 2] No such file or directory: './demo' './demo' filename is set with the following code in Modules/posixmodule.c: if (err_code) { errno = err_code; PyErr_SetFromErrnoWithFilenameObject(PyExc_OSError,

[issue43113] os.posix_spawn errors with wrong information when shebang points to not-existing file

2021-02-03 Thread STINNER Victor
STINNER Victor added the comment: If you want to look for the "demo" program in the PATH environment variable, use os.posix_spawnp() instead: https://docs.python.org/dev/library/os.html#os.posix_spawnp -- ___ Python tracker

[issue43113] os.posix_spawn errors with wrong information when shebang points to not-existing file

2021-02-03 Thread STINNER Victor
STINNER Victor added the comment: os.posix_spawn() is a thin wrapper to posix_spawn(). Python doesn't try to change its behavior on purpose. So I don't think that this issue is a Python bug. -- nosy: +vstinner ___ Python tracker

[issue43113] os.posix_spawn errors with wrong information when shebang points to not-existing file

2021-02-03 Thread Miro Hrončok
Miro Hrončok added the comment: I don't think posix_spawn actually reads $PATH (hence the second example is pretty much doing the same as the first one), but this problem also manifests with subprocess (which does). -- ___ Python tracker

[issue43113] os.posix_spawn errors with wrong information when shebang points to not-existing file

2021-02-03 Thread Miro Hrončok
Change by Miro Hrončok : -- nosy: +hroncok title: os.posix_spawn errors with wrong information when shebang does not exist -> os.posix_spawn errors with wrong information when shebang points to not-existing file ___ Python tracker