From 57bd8c6f873f84aea1f4f60bef2ef17071be641a Mon Sep 17 00:00:00 2001 From: Ronan Pigott Date: Wed, 6 Sep 2023 14:22:48 -0700 Subject: [PATCH] gh-109033: Return filename with os.utime errors The filename was previously intentionally omitted from exception becuase "it might confuse the user". Uncaught exceptions are not generally a replacement for user-facing error messages, so obscuring this information only has the effect of making the programmer's life more difficult. --- Modules/posixmodule.c | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/Modules/posixmodule.c b/Modules/posixmodule.c index c4340397fbe577c..f67257bb22f5e23 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); + PyErr_SetFromWindowsErrWithFilename(0, path->wide); 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(); + posix_path_error(path); return NULL; }