python / cpython

The Python programming language
https://www.python.org
Other
63.34k stars 30.32k forks source link

Include the current working dir in FileNotFoundError #93431

Open UlrichEckhardt opened 2 years ago

UlrichEckhardt commented 2 years ago

Feature or enhancement

A FileNotFoundError exception should include the current working directory when referring to a relative path.

Pitch

The problem this solves is with relative paths. If you just get the error "foo/bar not found", it is not enough info to fully understand the problem, because whether this can be found depends on the working directory as well.

At the moment, I'm working with Bazel (a build system), which does its form of sandboxing by symlinking things into a separate directory and building there. This implies both creating files/symlinks and switching directories and a lot of that. When a file is not found, it can mean that either of the two operations were faulty, but with a relative path you absolutely need the working directory to say which is the case.

Note that there is another category of similar problems, where e.g. Popen() tries to locate an executable using the PATH environment variable. Here, the simple executable file name is not helpful without the directories that were searched.

Previous discussion

I have found #60389, which is also related to missing info in such an error. Apart from that, I haven't found any similar discussions.

Linked PRs

tiran commented 2 years ago

For openat(2) and similar *at syscalls we would have to include the dirfd file descriptor if the dirfd argument is not AT_FDCWD. getcwd(3) would give incorrect answer.