Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 33a6da9

Browse files
committed
Fix for bug #110670 - Win32 os.listdir raises confusing errors:
The existing win32_error() function now returns the new(ish) WindowsError, ensuring we get correct error messages.
1 parent 557a044 commit 33a6da9

1 file changed

Lines changed: 7 additions & 3 deletions

File tree

Modules/posixmodule.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -349,12 +349,16 @@ posix_error_with_filename(char* name)
349349
static PyObject *
350350
win32_error(char* function, char* filename)
351351
{
352-
/* XXX this could be improved */
352+
/* XXX We should pass the function name along in the future.
353+
(_winreg.c also wants to pass the function name.)
354+
This would however require an additional param to the
355+
Windows error object, which is non-trivial.
356+
*/
353357
errno = GetLastError();
354358
if (filename)
355-
return PyErr_SetFromErrnoWithFilename(PyExc_OSError, filename);
359+
return PyErr_SetFromWindowsErrWithFilename(errno, filename);
356360
else
357-
return PyErr_SetFromErrno(PyExc_OSError);
361+
return PyErr_SetFromWindowsErr(errno);
358362
}
359363
#endif
360364

0 commit comments

Comments
 (0)