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/stringer: internal error when importing go packages on go1.18 for Linux #51924

Closed
avislash opened this issue Mar 24, 2022 · 4 comments
Labels
FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. Tools This label describes issues relating to any tools in the x/tools repository. WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided.
Milestone

Comments

@avislash
Copy link

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

$ go version
go version go1.18 linux/amd64

Does this issue reproduce with the latest release?

Yes

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

Ubuntu 20.04 LTS (Linux ubhold 5.11.0-46-generic #51~20.04.1-Ubuntu SMP Fri Jan 7 06:51:40 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux)

NOTE: This works as expected on Mac OS. This only appears to be a problem on Linux and this was working fine before with go1.17.

go env Output
$ go env
GO111MODULE="on"
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/redacted/.cache/go-build"
GOENV="/home/redacted/.config/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GOMODCACHE="/home/redacted/go/pkg/mod"
GONOPROXY="github.com/redacted*"
GONOSUMDB="github.com/redacted/*"
GOOS="linux"
GOPATH="/home/redacted/go"
GOPRIVATE="github.com/redacted/*"
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/lib/go-1.18"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/lib/go-1.18/pkg/tool/linux_amd64"
GOVCS=""
GOVERSION="go1.18"
GCCGO="gccgo"
GOAMD64="v1"
AR="ar"
CC="gcc"
CXX="/usr/bin/g++-7"
CGO_ENABLED="1"
GOMOD="/home/redacted/go_tutorial/stringer_is_broke_af/go.mod"
GOWORK=""
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-build4289626171=/tmp/go-build -gno-record-gcc-switches"

What did you do?

I tried to use stringer to auto-generate the Stringer interface for an enum using go1.18 (installed via APT) on Ubuntu 20.04 LTS.

Using go generate or just running stringer on the code below reproduces the error for me

//go:generate stringer -type=Foo -trimprefix Foo
package main

import "fmt"
type Foo uint64
const (
    FooZero Foo = iota
    FooOne
    FooTwo
)

func main() {
    var f Foo
    fmt.Println(f)
}

If I remove the "fmt" import and instead just use a print() I get no errors.

//go:generate stringer -type=Foo -trimprefix Foo
package main

type Foo uint64
const (
    FooZero Foo = iota
    FooOne
    FooTwo
)

func main() {
    var f Foo
    print(f)
}

What did you expect to see?

I expected to see a file called foo_string.go that implements a String() method for the Foo enum

What did you see instead?

$ go generate .
stringer: internal error: package "fmt" without types was imported from "stringer_is_broke_af"
main.go:1: running "stringer": exit status 1
@seankhliao
Copy link
Member

what version of stringer?

@mknyszek
Copy link
Contributor

Is this issue new in Go 1.18?

@mknyszek mknyszek changed the title Stringer Internal Error when importing go packages on go1.18 for Linux x/tools/cmd/stringer: internal error when importing go packages on go1.18 for Linux Mar 24, 2022
@gopherbot gopherbot added the Tools This label describes issues relating to any tools in the x/tools repository. label Mar 24, 2022
@mknyszek mknyszek added NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. and removed Tools This label describes issues relating to any tools in the x/tools repository. labels Mar 24, 2022
@gopherbot gopherbot added this to the Unreleased milestone Mar 24, 2022
@mknyszek mknyszek modified the milestones: Unreleased, Backlog Mar 24, 2022
@mknyszek
Copy link
Contributor

CC @golang/tools-team

@mknyszek mknyszek added the Tools This label describes issues relating to any tools in the x/tools repository. label Mar 24, 2022
@mknyszek mknyszek modified the milestones: Backlog, Unreleased Mar 24, 2022
@seankhliao seankhliao added the WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided. label Mar 24, 2022
@avislash
Copy link
Author

avislash commented Mar 24, 2022

Thanks for the prompt response! I figured out the root issue, it turns out the stringer binary was not being updated when I tried to update to golang.org/x/tools v0.1.10.

I had to blow away stringer in go/bin/ and then reinstall using go install golang.org/x/tools/cmd/stringer@latest.

Once I did this I was able to use go generate again.

I'm still not really sure why this manifested in Linux and not in Mac OS.

@golang golang locked and limited conversation to collaborators Mar 24, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. Tools This label describes issues relating to any tools in the x/tools repository. WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided.
Projects
None yet
Development

No branches or pull requests

4 participants