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

Open
bcmills opened this issue May 7, 2020 · 2 comments
Open

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

bcmills opened this issue May 7, 2020 · 2 comments
Assignees
Labels
Milestone

Comments

@bcmills
Copy link
Member

@bcmills 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 label May 7, 2020
@bcmills bcmills added this to the Go1.16 milestone May 7, 2020
@bcmills
Copy link
Member Author

@bcmills 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

@gopherbot gopherbot commented May 13, 2020

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.