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

Skip to content

Commit 9f064ec

Browse files
committed
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.
1 parent f9bd6e4 commit 9f064ec

File tree

2 files changed

+4
-7
lines changed

2 files changed

+4
-7
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Exceptions raised by os.utime builtin function now include the related
2+
filename

Modules/posixmodule.c

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6307,11 +6307,7 @@ os_utime_impl(PyObject *module, path_t *path, PyObject *times, PyObject *ns,
63076307
_Py_time_t_to_FILE_TIME(utime.mtime_s, utime.mtime_ns, &mtime);
63086308
}
63096309
if (!SetFileTime(hFile, NULL, &atime, &mtime)) {
6310-
/* Avoid putting the file name into the error here,
6311-
as that may confuse the user into believing that
6312-
something is wrong with the file, when it also
6313-
could be the time stamp that gives a problem. */
6314-
PyErr_SetFromWindowsErr(0);
6310+
PyErr_SetFromWindowsErrWithFilename(0, path->wide);
63156311
CloseHandle(hFile);
63166312
return NULL;
63176313
}
@@ -6351,8 +6347,7 @@ os_utime_impl(PyObject *module, path_t *path, PyObject *times, PyObject *ns,
63516347
#endif
63526348

63536349
if (result < 0) {
6354-
/* see previous comment about not putting filename in error here */
6355-
posix_error();
6350+
posix_path_error(path);
63566351
return NULL;
63576352
}
63586353

0 commit comments

Comments
 (0)