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 vstinner
Recipients Raúl Núñez de Arenas, eryksun, paul.moore, steve.dower, tim.golden, vstinner, zach.ware
Date 2016-03-08.11:54:21
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1457438062.49.0.418258419527.issue26493@psf.upfronthosting.co.za>
In-reply-to
Content
> 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 ;-)
History
Date User Action Args
2016-03-08 11:54:22vstinnersetrecipients: + vstinner, paul.moore, tim.golden, zach.ware, eryksun, steve.dower, Raúl Núñez de Arenas
2016-03-08 11:54:22vstinnersetmessageid: <1457438062.49.0.418258419527.issue26493@psf.upfronthosting.co.za>
2016-03-08 11:54:22vstinnerlinkissue26493 messages
2016-03-08 11:54:21vstinnercreate