This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author a.badger
Recipients Matthew Tanous, a.badger, vstinner
Date 2019-05-08.12:52:52
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1557319972.44.0.118280246397.issue36812@roundup.psfhosted.org>
In-reply-to
Content
Yeah, I've verified what Victor said about the OS not giving us enough information to tell what file is causing the issue.  However, I wonder if we should change the error message to be less confusing?  I'm a godawful C programmer but maybe something like this:

-        PyErr_SetFromErrnoWithFilenameObject(PyExc_OSError, path->object);
+        if (file_actionsp != NULL) {
+            /* OSErrors can be triggered by the program being invoked or by a
+             * problem with the files in file_actions.  Change the default
+             * error message so as not to confuse the programmer
+             */
+            if (path->narrow != NULL) {
+                char *err_msg_fmt = "While spawning %s\0";
+                unsigned int err_msg_size = strlen(path->narrow) + strlen(err_msg_fmt) + 1;
+                char* err_msg = malloc(err_msg_size);
+
+                PyOS_snprintf(err_msg, err_msg_size, err_msg_fmt, path->narrow);
+                /* Slight abuse, we're sending an error message rather than
+                 * a filename
+                 */
+                PyErr_SetFromErrnoWithFilename(PyExc_OSError, err_msg);
+            }
+        }
+        else
+        {
+            PyErr_SetFromErrnoWithFilenameObject(PyExc_OSError, path->object);
+        }


Which leads to output like this:

>>> import os
>>> file_actions = [(os.POSIX_SPAWN_OPEN, 1, '.tmp/temp_file', os.O_CREAT | os.O_RDWR, 777)]
>>> os.posix_spawnp('whoami', ['whoami'], os.environ, file_actions=file_actions)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
FileNotFoundError: [Errno 2] No such file or directory: 'While spawning whoami'


I can submit a PR for that and people can teach me how to fix my C if it's considered useful.
History
Date User Action Args
2019-05-08 12:52:52a.badgersetrecipients: + a.badger, vstinner, Matthew Tanous
2019-05-08 12:52:52a.badgersetmessageid: <1557319972.44.0.118280246397.issue36812@roundup.psfhosted.org>
2019-05-08 12:52:52a.badgerlinkissue36812 messages
2019-05-08 12:52:52a.badgercreate