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

cmd/go: go generate unexpected EOF error when comment lacks newline at EOF #32607

Closed
logan opened this issue Jun 13, 2019 · 8 comments
Closed
Labels
FrozenDueToAge WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided.

Comments

@logan
Copy link

logan commented Jun 13, 2019

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

$ go version
go version go1.12.6 darwin/amd64

What did you do?

$ echo -e -n 'package main\n//go:generate true' > gen.go
$ go generate ./gen.go
gen.go:2: error reading gen.go: unexpected EOF
$ echo >> gen.go
$ go generate ./gen.go
$
@ianlancetaylor
Copy link
Contributor

This is working as designed. Why do you think it is a bug? go generate expects a go:generate comment to be a normal line comment ending at a newline.

@ianlancetaylor ianlancetaylor added the WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided. label Jun 13, 2019
@logan
Copy link
Author

logan commented Jun 13, 2019

Where is that expectation documented? I don't see that it's a necessary or useful requirement, and it's confusing to encounter in the wild.

I have a small patch to fix this ready (once I sort out CLA concerns with my employer). When an EOF is encountered, the generate comment has been read into a buffer. All it needs is a '\n' appended to it to parse and exec, but the current implementation returns io.ErrUnexpectedEOF instead.

@logan
Copy link
Author

logan commented Jun 13, 2019

I forgot to mention when I filed this issue, I'm not the first person to run into this. See #18066.

@ianlancetaylor
Copy link
Contributor

Let's just define go generate as requiring a full line comment ending in a newline, and move on.

@ianlancetaylor
Copy link
Contributor

(If you want to send a very short doc change, we can consider it.)

@logan
Copy link
Author

logan commented Jun 21, 2019

The only documentation I'm aware of is here: https://golang.org/pkg/cmd/go/internal/generate/

As someone who supports multiple generators for a number of other developers, this is an error I'm likely to be dealing with again. My users are unlikely to be viewing the godocs for that internal package.

In my opinion, if go fmt doesn't force newlines at the end of files (#1178), then go generate shouldn't require them.

I suppose this issue doesn't matter. It's small and the fix is trivial and I'll post it up for review as soon as my employer allows me to.

@ianlancetaylor
Copy link
Contributor

I think you are misreading #1178. gofmt does ensure that a Go file ends with a newline.

> echo -e -n 'package main\n//go:generate true' > gen.go
> cat -ve gen.go
package main$
//go:generate true> gofmt -w gen.go
> cat -ve gen.go
package main$
$
//go:generate true$

@logan
Copy link
Author

logan commented Jun 21, 2019

Ah, my mistake. I guess my colleague who encountered this must not have integrated go fmt with GoLand in the way I expected.

@golang golang locked and limited conversation to collaborators Jun 20, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided.
Projects
None yet
Development

No branches or pull requests

3 participants