[issue26493] Bad formatting in WinError 193 when using subprocess.check_call

Eryk Sun report at bugs.python.org
Tue Apr 30 20:12:53 EDT 2019


Eryk Sun <eryksun at gmail.com> 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>".

I suggested creating a new issue to fix the calls that omit this flag. I think it's just two modules: Modules/overlapped.c and Modules/_ctypes/callproc.c. If there are more inserts than arguments (i.e. any inserts in our case since we pass no arguments), then FormatMessageW fails and the above modules use a default message. For example:

    >>> _overlapped.FormatMessage(193)
    'unknown error code 193'
    >>> _ctypes.FormatError(193)
    '<no description>'

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

I meant that Popen._execute_child would handle the exception by modifying and reraising it. In general for OSError exceptions, we could set `filename` to either `executable`, if it's defined, or else parse it out of the commandline. For ERROR_BAD_EXE_FORMAT (193), we could also change `strerror` to something like "Invalid executable format" instead of "%1 is not a valid Win32 application". This is more consistent with how we append ": {filename}" to the message.

----------

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue26493>
_______________________________________


More information about the Python-bugs-list mailing list