Toshio Kuratomi <a.bad...@gmail.com> added the comment:

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.

----------

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue36812>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to