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

x/tools/cmd/goimports: truncates input file despite no -w flag #28270

Closed
myitcv opened this issue Oct 18, 2018 · 3 comments
Closed

x/tools/cmd/goimports: truncates input file despite no -w flag #28270

myitcv opened this issue Oct 18, 2018 · 3 comments
Assignees
Milestone

Comments

@myitcv
Copy link
Member

@myitcv myitcv commented Oct 18, 2018

Please answer these questions before submitting your issue. Thanks!

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

go version go1.11.1 linux/amd64

Using goimports as of https://go-review.googlesource.com/c/tools/+/142697, specifically patch set 5:

git fetch https://go.googlesource.com/tools refs/changes/97/142697/5 && git checkout FETCH_HEAD

Does this issue reproduce with the latest release?

Yes

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

GOARCH="amd64"
GOBIN=""
GOCACHE="/home/myitcv/.cache/go-build"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/home/myitcv/gostuff"
GOPROXY=""
GORACE=""
GOROOT="/home/myitcv/gos"
GOTMPDIR=""
GOTOOLDIR="/home/myitcv/gos/pkg/tool/linux_amd64"
GCCGO="gccgo"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD=""
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build893028818=/tmp/go-build -gno-record-gcc-switches"

What did you do?

goimports was "hanging" on this input file so I switched out of my editor and ran this sequence of commands:

$ goimports main.go
(killed with Ctrl-c)
$ gofmt main.go
...
$ goimports -help
...
$ goimports -v -trace main.go
(killed with Ctrl-c)
$ goimports -v main.go 

This last call ran very fast; too fast because main.go had, by this point, been truncated to zero length.

Unfortunately I can't provide a precise repo because the contents of the truncated file have been lost 😄

What did you expect to see?

The input file not to be truncated; no -w flag was provided.

What did you see instead?

Per above.

cc @ianthehat @heschik

@myitcv myitcv added the modules label Oct 18, 2018
@gopherbot gopherbot added this to the Unreleased milestone Oct 18, 2018
@myitcv
Copy link
Member Author

@myitcv myitcv commented Oct 18, 2018

Just to be clear, I'm not 100% sure goimports is the cause of the issue here; just logging a report with a best-efforts set of repro steps in case others see something similar.

@heschik
Copy link
Contributor

@heschik heschik commented Oct 18, 2018

goimports -v -trace main.go

-trace takes an argument, the name of the trace file to write. So you asked it to write a trace file to main.go, fix the imports of stdin, and then killed it before giving it any code on stdin to format.

All WAI AFAIK.

@heschik heschik closed this Oct 18, 2018
@myitcv
Copy link
Member Author

@myitcv myitcv commented Oct 18, 2018

Oh wow. Total user error. Thanks for humouring me with a response 😄

@golang golang locked and limited conversation to collaborators Oct 18, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

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