Skip to content

os/dir: File.Readdir claims it will return an error on empty slice, but doesn't #16919

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

Closed
euank opened this issue Aug 29, 2016 · 1 comment
Closed
Milestone

Comments

@euank
Copy link
Contributor

euank commented Aug 29, 2016

The current doc comment for File.Readdir here states that when n > 0, the error value will be populated if no FileInfo is returned. The reproduction I linked below clearly shows this isn't always the case, at least with the dir_unix.go implementation of it here.

It is trivial to reproduce this using the following example program: https://gist.github.com/euank/72cc2f1d13630eecd5459d8fe68e60b6

Should the documentation be changed, or should the implementation be fixed to error correctly if the implementation-specific method did not behave as the documentation suggests it should?
I'd be happy to submit a patch for this either way.

What version of Go are you using (go version)?

go version devel +e6f9f39 Mon Aug 29 18:25:33 2016 +0000 linux/amd64

What operating system and processor architecture are you using (go env)?

amd64, linux

What did you do?

# Download the repro from https://gist.github.com/euank/72cc2f1d13630eecd5459d8fe68e60b6
$ go run readdir_bug.go | grep "this is a bug"
Observed err=<nil> and files=[]; this is a bug
@bradfitz bradfitz self-assigned this Aug 29, 2016
@bradfitz bradfitz added this to the Go1.8 milestone Aug 29, 2016
euank added a commit to euank/go that referenced this issue Aug 29, 2016
@gopherbot
Copy link
Contributor

CL https://golang.org/cl/28056 mentions this issue.

@golang golang locked and limited conversation to collaborators Aug 30, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants