-
Notifications
You must be signed in to change notification settings - Fork 18k
io/ioutil: WriteFile example errors when run on the Go Playground #40623
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
Comments
You're right! In the background, I think that we could indeed change the example. I'm not sure about documenting this behavior though since we don't explicitly mention anything about directories there. |
/cc @dmitshur |
The testdata directory exists on disk. However, the example doesn’t have an // Output comment, so it’s only meant to be compiled and displayed in documentation, but not executed:
It doesn’t work on the Go Playground because the testdata directory isn’t available in that environment. But given there isn’t an // Output comment, maybe there shouldn’t be a button to run it on the website. |
@dmitshur the issue isn't really about the playground but that the example as written doesn't work without other steps that are not included here, like "must have this directory before running this code" |
Seems like duplicate of #32916 fixed by https://golang.org/cl/284452 |
What version of Go are you using (
go version
)?latest
Does this issue reproduce with the latest release?
yes
What operating system and processor architecture are you using (
go env
)?Go Playground https://play.golang.org/
What did you do?
run example at https://golang.org/pkg/io/ioutil/#WriteFile which links to https://play.golang.org/p/bIP2HMSXz1u
What did you expect to see?
no error
What did you see instead?
error: `open testdata/hello: no such file or directory
Suggested Fixes
WriteFile
does not create a directory, and the code example tries to write to the non-existent directorytestdata
. Possible solution are either to create this directory in the example code or change the argument toWriteFile
to just include the file nameThe text was updated successfully, but these errors were encountered: