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: operates in -v (verbose) mode even when flag isn't set #37636

Closed
BentCoder opened this issue Mar 3, 2020 · 14 comments
Closed

Comments

@BentCoder
Copy link

@BentCoder BentCoder commented Mar 3, 2020

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

$ go version
go version go1.13 darwin/amd64

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

go env Output
$ go env
GO111MODULE="on"
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/me/Library/Caches/go-build"
GOENV="/Users/me/Library/Application Support/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GONOPROXY=""
GONOSUMDB=""
GOOS="darwin"
GOPATH="/Users/me/Server/Go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/local/Cellar/go/1.13/libexec"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/Cellar/go/1.13/libexec/pkg/tool/darwin_amd64"
GCCGO="gccgo"
AR="ar"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD="/Users/me/Server/Go/src/github.com/me/going/go.mod"
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 -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/pr/g7230wl10mnf0fnqd6cc1_f80000gn/T/go-build238294966=/tmp/go-build -gno-record-gcc-switches -fno-common"

What did you do?

I haven't changed anything since yesterday but today when I run goimports -w . I started getting message below.

goimports -w . 2020/03/03 20:27:52 fixImports(filename="pkg/database/database.go"), abs="/Users/me/Server/Go/src/github.com/me/going/pkg/database/database.go", srcDir="/Users/me/Server/Go/src/github.com/me/going/pkg/database" ...

What did you expect to see?

Definitely not the message above.

What did you see instead?

Many lines of fixImports lines as shown above. Wondering what has changed in last a few hours?

@dmitshur
Copy link
Member

@dmitshur dmitshur commented Mar 3, 2020

What version of the goimports binary are you using? Where and when did you install it from?

@BentCoder
Copy link
Author

@BentCoder BentCoder commented Mar 3, 2020

Here is the full output.

$ go get golang.org/x/tools/cmd/goimports

go: finding golang.org/x/tools latest
go: downloading golang.org/x/tools v0.0.0-20200303202040-658b03bcd3d8
go: extracting golang.org/x/tools v0.0.0-20200303202040-658b03bcd3d8
go: downloading golang.org/x/mod v0.2.0
go: extracting golang.org/x/mod v0.2.0
go: downloading golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543
go: extracting golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543
go: finding golang.org/x/mod v0.2.0
go: finding golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543

$ goimports -w .

2020/03/03 20:46:23 fixImports(filename="pkg/database/database.go"), abs="/Users/me/Server/Go/src/github.com/me/golibrary/pkg/database/database.go", srcDir="/Users/me/Server/Go/src/github.com/me/golibrary/pkg/database" ...
2020/03/03 20:46:23 fixImports(filename="pkg/database/offset.go"), abs="/Users/me/Server/Go/src/github.com/me/golibrary/pkg/database/offset.go", srcDir="/Users/me/Server/Go/src/github.com/me/golibrary/pkg/database" ...
2020/03/03 20:46:23 fixImports(filename="pkg/logger/logger.go"), abs="/Users/me/Server/Go/src/github.com/me/golibrary/pkg/logger/logger.go", srcDir="/Users/me/Server/Go/src/github.com/me/golibrary/pkg/logger" ...
2020/03/03 20:46:23 fixImports(filename="pkg/middleware/middleware.go"), abs="/Users/me/Server/Go/src/github.com/me/golibrary/pkg/middleware/middleware.go", srcDir="/Users/me/Server/Go/src/github.com/me/golibrary/pkg/middleware" ...
2020/03/03 20:46:23 fixImports(filename="pkg/middleware/panicrecovery.go"), abs="/Users/me/Server/Go/src/github.com/me/golibrary/pkg/middleware/panicrecovery.go", srcDir="/Users/me/Server/Go/src/github.com/me/golibrary/pkg/middleware" ...
2020/03/03 20:46:23 fixImports(filename="pkg/middleware/request.go"), abs="/Users/me/Server/Go/src/github.com/me/golibrary/pkg/middleware/request.go", srcDir="/Users/me/Server/Go/src/github.com/me/golibrary/pkg/middleware" ...
2020/03/03 20:46:23 fixImports(filename="pkg/request/request.go"), abs="/Users/me/Server/Go/src/github.com/me/golibrary/pkg/request/request.go", srcDir="/Users/me/Server/Go/src/github.com/me/golibrary/pkg/request" ...
2020/03/03 20:46:23 fixImports(filename="pkg/response/response.go"), abs="/Users/me/Server/Go/src/github.com/me/golibrary/pkg/response/response.go", srcDir="/Users/me/Server/Go/src/github.com/me/golibrary/pkg/response" ...
2020/03/03 20:46:23 fixImports(filename="pkg/router/router.go"), abs="/Users/me/Server/Go/src/github.com/me/golibrary/pkg/router/router.go", srcDir="/Users/me/Server/Go/src/github.com/me/golibrary/pkg/router" ...
2020/03/03 20:46:23 fixImports(filename="pkg/test/database.go"), abs="/Users/me/Server/Go/src/github.com/me/golibrary/pkg/test/database.go", srcDir="/Users/me/Server/Go/src/github.com/me/golibrary/pkg/test" ...
2020/03/03 20:46:23 fixImports(filename="pkg/validator/datetime.go"), abs="/Users/me/Server/Go/src/github.com/me/golibrary/pkg/validator/datetime.go", srcDir="/Users/me/Server/Go/src/github.com/me/golibrary/pkg/validator" ...
2020/03/03 20:46:23 fixImports(filename="pkg/validator/password.go"), abs="/Users/me/Server/Go/src/github.com/me/golibrary/pkg/validator/password.go", srcDir="/Users/me/Server/Go/src/github.com/me/golibrary/pkg/validator" ...
@dmitshur dmitshur changed the title goimports: fixImports(filename= x/tools/cmd/goimports: unexpected "fixImports(...)" error from goimports -w . Mar 3, 2020
@gopherbot gopherbot added this to the Unreleased milestone Mar 3, 2020
@gopherbot gopherbot added the Tools label Mar 3, 2020
@gopherbot gopherbot added the Tools label Mar 3, 2020
@dmitshur
Copy link
Member

@dmitshur dmitshur commented Mar 3, 2020

Thanks. Which directory are you running goimports -w . in? What are its contents?

/cc @bradfitz per owners. Also /cc @heschik.

@BentCoder
Copy link
Author

@BentCoder BentCoder commented Mar 3, 2020

I am just running in the application directory. I have a few apps and they all produce same result. Some are web apps and some are just libraries.

@BentCoder
Copy link
Author

@BentCoder BentCoder commented Mar 3, 2020

It started happening today roughly about 6 hours ago if I am not wrong.

@codyoss
Copy link
Member

@codyoss codyoss commented Mar 3, 2020

goimports -l . seems to be reporting incorrectly as well. Noticed this in our CI as well in google-cloud-go.

@dmitshur
Copy link
Member

@dmitshur dmitshur commented Mar 3, 2020

I can reproduce with the latest x/tools commit:

tools $ go run ./cmd/goimports -w ./go/ast
2020/03/03 16:12:42 fixImports(filename="go/ast/astutil/enclosing.go"), abs="/Users/dmitshur/go/src/golang.org/x/tools/go/ast/astutil/enclosing.go", srcDir="/Users/dmitshur/go/src/golang.org/x/tools/go/ast/astutil" ...
2020/03/03 16:12:42 fixImports(filename="go/ast/astutil/enclosing_test.go"), abs="/Users/dmitshur/go/src/golang.org/x/tools/go/ast/astutil/enclosing_test.go", srcDir="/Users/dmitshur/go/src/golang.org/x/tools/go/ast/astutil" ...
2020/03/03 16:12:42 fixImports(filename="go/ast/astutil/imports.go"), abs="/Users/dmitshur/go/src/golang.org/x/tools/go/ast/astutil/imports.go", srcDir="/Users/dmitshur/go/src/golang.org/x/tools/go/ast/astutil" ...
2020/03/03 16:12:42 fixImports(filename="go/ast/astutil/imports_test.go"), abs="/Users/dmitshur/go/src/golang.org/x/tools/go/ast/astutil/imports_test.go", srcDir="/Users/dmitshur/go/src/golang.org/x/tools/go/ast/astutil" ...
2020/03/03 16:12:42 fixImports(filename="go/ast/astutil/rewrite.go"), abs="/Users/dmitshur/go/src/golang.org/x/tools/go/ast/astutil/rewrite.go", srcDir="/Users/dmitshur/go/src/golang.org/x/tools/go/ast/astutil" ...
2020/03/03 16:12:42 fixImports(filename="go/ast/astutil/rewrite_test.go"), abs="/Users/dmitshur/go/src/golang.org/x/tools/go/ast/astutil/rewrite_test.go", srcDir="/Users/dmitshur/go/src/golang.org/x/tools/go/ast/astutil" ...
2020/03/03 16:12:42 fixImports(filename="go/ast/astutil/util.go"), abs="/Users/dmitshur/go/src/golang.org/x/tools/go/ast/astutil/util.go", srcDir="/Users/dmitshur/go/src/golang.org/x/tools/go/ast/astutil" ...
2020/03/03 16:12:42 fixImports(filename="go/ast/inspector/inspector.go"), abs="/Users/dmitshur/go/src/golang.org/x/tools/go/ast/inspector/inspector.go", srcDir="/Users/dmitshur/go/src/golang.org/x/tools/go/ast/inspector" ...
2020/03/03 16:12:42 fixImports(filename="go/ast/inspector/inspector_test.go"), abs="/Users/dmitshur/go/src/golang.org/x/tools/go/ast/inspector/inspector_test.go", srcDir="/Users/dmitshur/go/src/golang.org/x/tools/go/ast/inspector" ...
2020/03/03 16:12:42 fixImports(filename="go/ast/inspector/typeof.go"), abs="/Users/dmitshur/go/src/golang.org/x/tools/go/ast/inspector/typeof.go", srcDir="/Users/dmitshur/go/src/golang.org/x/tools/go/ast/inspector" ...

But not 6 commits ago:

tools $ git co 9b52d559c6099a25c1e7b2b4b3d14a51a3463215
HEAD is now at 9b52d559 internal/lsp/regtest: add a test for diagnostics on first file
tools $ go run ./cmd/goimports -w ./go/ast             
tools $ 

It seems this has started to happen as of CL 221557. /cc @heschik @stamblerre

@dmitshur dmitshur added the Soon label Mar 3, 2020
@dmitshur
Copy link
Member

@dmitshur dmitshur commented Mar 3, 2020

Based on the contents of that CL and some local testing, I see that goimports is still doing the right thing (it correctly formats .go files and exits with zero exit code), it's just emitting unwanted messages to stderr.

@dmitshur dmitshur changed the title x/tools/cmd/goimports: unexpected "fixImports(...)" error from goimports -w . x/tools/cmd/goimports: prints unexpected "fixImports(...)" messages to stderr Mar 3, 2020
@stamblerre
Copy link
Contributor

@stamblerre stamblerre commented Mar 3, 2020

Thanks for investigating this. I'll take a look and send out a CL.

@dmitshur
Copy link
Member

@dmitshur dmitshur commented Mar 3, 2020

Thanks @stamblerre.

@dmitshur dmitshur changed the title x/tools/cmd/goimports: prints unexpected "fixImports(...)" messages to stderr x/tools/cmd/goimports: operates in -v (verbose) mode even when flag isn't set Mar 3, 2020
@gopherbot
Copy link

@gopherbot gopherbot commented Mar 3, 2020

Change https://golang.org/cl/221918 mentions this issue: internal/imports: don't set a logger unless the user has provided it

@BentCoder
Copy link
Author

@BentCoder BentCoder commented Mar 3, 2020

I see this has been closed now but what should I, everybody else, do about? Sit tight and wait?

@stamblerre
Copy link
Contributor

@stamblerre stamblerre commented Mar 3, 2020

go get golang.org/x/tools/cmd/goimports should give you the updated version.

@codyoss
Copy link
Member

@codyoss codyoss commented Mar 3, 2020

Thank you for your fast turn around!

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
5 participants
You can’t perform that action at this time.