diff --git a/Misc/NEWS.d/next/Library/2023-09-06-14-47-28.gh-issue-109033.piUzDx.rst b/Misc/NEWS.d/next/Library/2023-09-06-14-47-28.gh-issue-109033.piUzDx.rst new file mode 100644 index 000000000000000..15ec0b437d4339f --- /dev/null +++ b/Misc/NEWS.d/next/Library/2023-09-06-14-47-28.gh-issue-109033.piUzDx.rst @@ -0,0 +1,2 @@ +Exceptions raised by os.utime builtin function now include the related +filename diff --git a/Modules/posixmodule.c b/Modules/posixmodule.c index c4340397fbe577c..2c89a68fa57f2e6 100644 --- a/Modules/posixmodule.c +++ b/Modules/posixmodule.c @@ -6307,11 +6307,7 @@ os_utime_impl(PyObject *module, path_t *path, PyObject *times, PyObject *ns, _Py_time_t_to_FILE_TIME(utime.mtime_s, utime.mtime_ns, &mtime); } if (!SetFileTime(hFile, NULL, &atime, &mtime)) { - /* Avoid putting the file name into the error here, - as that may confuse the user into believing that - something is wrong with the file, when it also - could be the time stamp that gives a problem. */ - PyErr_SetFromWindowsErr(0); + path_error(path); CloseHandle(hFile); return NULL; } @@ -6351,8 +6347,7 @@ os_utime_impl(PyObject *module, path_t *path, PyObject *times, PyObject *ns, #endif if (result < 0) { - /* see previous comment about not putting filename in error here */ - posix_error(); + path_error(path); return NULL; }