Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

os: (*File).Readdirnames returns an error that does not include the path #38923

Closed
bcmills opened this issue May 7, 2020 · 2 comments
Closed
Labels
FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done.
Milestone

Comments

@bcmills
Copy link
Contributor

bcmills commented May 7, 2020

In general, when *os.File methods fail they return a PathError referring to the failing operation and the name of the file:

go/src/os/stat_unix.go

Lines 20 to 23 in a38a917

err := f.pfd.Fstat(&fs.sys)
if err != nil {
return nil, &PathError{"stat", f.name, err}
}

Unfortunately, on Unix and Darwin, the Readdir and Readdirnames methods do not: instead, they returns a *os.SyscallError that does not include the path:

go/src/os/dir_unix.go

Lines 52 to 54 in a38a917

if errno != nil {
return names, wrapSyscallError("readdirent", errno)
}

go/src/os/dir_darwin.go

Lines 30 to 32 in a38a917

if errno != nil {
return nil, wrapSyscallError(call, errno)
}

This not only violates the general expectations for error descriptiveness in the standard library, but also makes the behavior inconsistent across platforms: Windows and Plan 9 both already return a *PathError from these methods.

CC @ianlancetaylor @bradfitz

@bcmills bcmills added the NeedsFix The path to resolution is known, but the work has not been done. label May 7, 2020
@bcmills bcmills added this to the Go1.16 milestone May 7, 2020
@bcmills
Copy link
Contributor Author

bcmills commented May 7, 2020

I think this is likely too invasive to fix in the 1.15 cycle, but I plan to address it in 1.16.

@bcmills bcmills self-assigned this May 7, 2020
@gopherbot
Copy link

Change https://golang.org/cl/233917 mentions this issue: os: return a *PathError from Readdirnames and Readdir on POSIX platforms

@golang golang locked and limited conversation to collaborators Aug 25, 2021
@rsc rsc unassigned bcmills Jun 23, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done.
Projects
None yet
Development

No branches or pull requests

2 participants