STINNER Victor added the comment:

> A new issue should be raised to fix the FormatMessage calls in the standard 
> library that mistakenly leave out FORMAT_MESSAGE_IGNORE_INSERTS.

Do you suggest to modify OSError constructor to modify the call to 
FormatMessageW(): don't pass the FORMAT_MESSAGE_IGNORE_INSERTS flag?

I prefer "%1 is not a valid Win32 application" message than "<no description>".

Currently, PyErr_SetFromErrnoWithFilenameObjects() doesn't pass any argument to 
FormatMessageW(). The problem is that it looks like the expected argument 
depends a lot of the failing system call. I don't think that it's ok to always 
pass the filename (or two filenames when we get two filenames, ex: os.rename) 
to FormatMessageW().

For example, _winapi.CreateProcess() doesn't pass any filename to OSError 
constructor.


> It would be possible for subprocess to replace "%1" with the filename parsed 
> from the command line and then re-raise the exception.

I like the idea of formatting the error message in the subprocess module. IMHO 
it's much safer to reformat the error message from the function which raises 
the exception, since the function knows the system call, has all parameters to 
the system call, and may expect some specific system calls.

There is no need to re-raise the exception: the "strerror" attribute contains 
the error message and it can be modified.

We need an helper function or add a new method to the OSError class. Example of 
method:

def reformat_strerror(self, *args):
   sef.strerror = FormatMessageW(..., self.strerror, ..., args)

For this specific issue, I don't know if reformat_strerror() should be called 
from subprocess.py or CreateProcess function of Modules/_winapi.c.

I understand that we should call reformat_strerror() with application_name 
(first parameter of CreateProcess, "executable" in subprocess), but only if the 
error message is 193.

Since there are "a lot" of error messages and a lot of functions calling system 
calls, I don't think that it will be possible to handle all possible error 
messages in all Python functions. I suggest to only call reformat_strerror() 
when an user complains, only promise best effort ;-)

----------

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

Reply via email to