[Python-bugs-list] [ python-Bugs-538827 ] Python open w/ MSVC6: bad error msgs

noreply@sourceforge.net noreply@sourceforge.net
Sun, 07 Apr 2002 01:00:53 -0800


Bugs item #538827, was opened at 2002-04-03 12:10
You can respond by visiting: 
http://sourceforge.net/tracker/?func=detail&atid=105470&aid=538827&group_id=5470

>Category: Windows
>Group: Platform-specific
Status: Open
Resolution: None
>Priority: 4
Submitted By: Greg Chapman (glchapman)
Assigned to: Tim Peters (tim_one)
Summary: Python open w/ MSVC6: bad error msgs

Initial Comment:
With the current Win32 build (actually, 2.2.1c1), you 
get the following behavior when feeding bad filenames 
to Python's open function:

>>> open("hello?.txt")
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
IOError: invalid argument: r

Apparently, VC6 maps the Win32 error 
ERROR_INVALID_NAME to EINVAL, and Python always treats 
this error as being related to the mode string.  It 
appears (from bug report 476593) that VC6 disagrees 
with GCC here; I don't know which compiler is right 
(actually, looking at the VC documentation for _open, 
it appears GCC is right).  At any rate, it appears 
Python cannot rely on EINVAL referring only to the 
mode string under Windows.

Interestingly, the current Python Win32 build also 
shows this:

>>> open("hello.txt", "x")
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
IOError: [Errno 0] Error: 'hello.txt'

When you actually provide a bad mode string, fopen 
fails, but it does not set errno.  (You can see this 
in the openfile function in _OPEN.C in the VC6 CRT 
source).  It might be possible to use this behavior to 
produce more accurate error messages under Windows.



----------------------------------------------------------------------

>Comment By: Tim Peters (tim_one)
Date: 2002-04-07 05:00

Message:
Logged In: YES 
user_id=31435

Which version of Windows are you using?  Here on Win98SE, I 
get

>>> open("hello?.txt")
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
IOError: [Errno 2] No such file or directory: 'hello?.txt'
>>>

all the way back through Python 2.0.  Note that MS's error 
translation table (in DOSMAP.C) doesn't contain an entry 
for ERROR_INVALID_NAME, so the logic in _dosmaperr() would 
return EINVAL in that case (it can't dream up anything 
better to return).  The errors CreateFile *can* trigger 
aren't documented, and I expect they vary across Windows 
flavors (and that Win98SE triggers ERROR_FILE_NOT_FOUND in 
this case, which maps to ENOENT).

Note that MS doesn't catch all senseless mode strings 
either.  For example,

>>> open('wtf', 'w hi greg!')
<open file 'wtf', mode 'w hi greg!' at 0x00768F30>
>>>

If you want to create a patch to clean up MS's mess here, 
be my guest.

----------------------------------------------------------------------

Comment By: Michael Hudson (mwh)
Date: 2002-04-03 12:15

Message:
Logged In: YES 
user_id=6656

Guess who gets to look at this one.


----------------------------------------------------------------------

You can respond by visiting: 
http://sourceforge.net/tracker/?func=detail&atid=105470&aid=538827&group_id=5470