Skip to content

os.utime raises exceptions without a filename. #109033

Closed
@rpigott

Description

@rpigott

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

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    type-bugAn unexpected behavior, bug, or error

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions