Closed
Description
Bug report
Bug description:
The builtin os.utime option raises exceptions without a filename. E.g. on Linux:
import os
try:
os.utime('/root', None)
except PermissionError as e:
print(e.filename) # None
The source actually provides a justification for this omission:
/* 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. */
which really is no justification at all.
Uncaught exceptions are not usually considered a replacement for user-facing error messages, so omitting the filename here is at best a guidance to the programmer, but this approach unnecessarily removes context that could be helpful in crafting a useful error message. On Linux at least, I don't even think that the exception traceback has the potential for confusion raised in this comment — EPERM could quite clearly mean that my user lacks the requisite permission to modify the file in whatever relevant way, including changing the timestamps.
CPython versions tested on:
3.11
Operating systems tested on:
Linux