Skip to content

BrokenImports runtime error: index out of range #2906

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

Closed
mbolt35 opened this issue Aug 1, 2023 · 4 comments
Closed

BrokenImports runtime error: index out of range #2906

mbolt35 opened this issue Aug 1, 2023 · 4 comments

Comments

@mbolt35
Copy link

mbolt35 commented Aug 1, 2023

What version of Go, VS Code & VS Code Go extension are you using?

Version Information
  • Run go version to get version of Go from the VS Code integrated terminal.
    • go version go1.20.6 linux/amd64
  • Run gopls -v version to get version of Gopls from the VS Code integrated terminal.
    • golang.org/x/tools/gopls v0.13.0
  • Run code -v or code-insiders -v to get version of VS Code or VS Code Insiders.
    • 1.80.2
    • 2ccd690cbff1569e4a83d7c43d45101f817401dc
    • x64
  • Check your installed extensions to get the version of the VS Code Go extension
    • v0.39.1
  • Run Ctrl+Shift+P (Cmd+Shift+P on Mac OS) > Go: Locate Configured Go Tools command.
        go:	/home/mbolt/sdk/go1.20.6/bin/go: go version go1.20.6 linux/amd64

	gotests:	/home/mbolt/go/bin/gotests	(version: v1.6.0 built with go: go1.20.6)
	gomodifytags:	/home/mbolt/go/bin/gomodifytags	(version: v1.16.0 built with go: go1.20.6)
	impl:	/home/mbolt/go/bin/impl	(version: v1.1.0 built with go: go1.20.6)
	goplay:	/home/mbolt/go/bin/goplay	(version: v1.0.0 built with go: go1.20.6)
	dlv:	/home/mbolt/go/bin/dlv	(version: v1.21.0 built with go: go1.20.6)
	staticcheck:	/home/mbolt/go/bin/staticcheck	(version: v0.4.3 built with go: go1.20.6)
	gopls:	/home/mbolt/go/bin/gopls	(version: v0.13.0 built with go: go1.20.6)

go env
Workspace Folder (opencost): /home/mbolt/dev/go/opencost
	GO111MODULE=""
	GOARCH="amd64"
	GOBIN=""
	GOCACHE="/home/mbolt/.cache/go-build"
	GOENV="/home/mbolt/.config/go/env"
	GOEXE=""
	GOEXPERIMENT=""
	GOFLAGS="-buildvcs=false"
	GOHOSTARCH="amd64"
	GOHOSTOS="linux"
	GOINSECURE=""
	GOMODCACHE="/home/mbolt/go/pkg/mod"
	GONOPROXY="github.com/kubecost"
	GONOSUMDB="github.com/kubecost"
	GOOS="linux"
	GOPATH="/home/mbolt/go"
	GOPRIVATE="github.com/kubecost"
	GOPROXY="direct"
	GOROOT="/home/mbolt/sdk/go1.20.6"
	GOSUMDB="sum.golang.org"
	GOTMPDIR=""
	GOTOOLDIR="/home/mbolt/sdk/go1.20.6/pkg/tool/linux_amd64"
	GOVCS=""
	GOVERSION="go1.20.6"
	GCCGO="gccgo"
	GOAMD64="v1"
	AR="ar"
	CC="gcc"
	CXX="g++"
	CGO_ENABLED="1"
	GOMOD="/home/mbolt/dev/go/opencost/go.mod"
	GOWORK=""
	CGO_CFLAGS="-O2 -g"
	CGO_CPPFLAGS=""
	CGO_CXXFLAGS="-O2 -g"
	CGO_FFLAGS="-O2 -g"
	CGO_LDFLAGS="-O2 -g"
	PKG_CONFIG="pkg-config"
	GOGCCFLAGS="-fPIC -m64 -pthread -Wl,--no-gc-sections -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build2357334639=/tmp/go-build -gno-record-gcc-switches"

Share the Go related settings you have added/edited

Run Preferences: Open Settings (JSON) command to open your settings.json file.
Share all the settings with the go. or ["go"] or gopls prefixes.

  "go.gopath": "/home/mbolt/go",
  "go.goroot": "/home/mbolt/sdk/go1.20.6",
  "go.buildFlags": [
    "-buildvcs=false"
  ],
  "go.testFlags": [
    "-v",
    "-count=1"
  ],
  "go.languageServerFlags": [
    "-rpc.trace",
    "-vv"
  ],
  "go.toolsManagement.autoUpdate": true,
  "go.useLanguageServer": true,
  "go.formatTool": "gofmt",
  "go.vetOnSave": "off",

Describe the bug

It is somewhat difficult to specifically point out exactly what the problem is, but this issue seems to have started with the latest VSCode update (I also updated go from 1.20.5 to 1.20.6 during the same timeframe), but in short, I'm getting many broken import problems that were not happening before, and the broken imports seem to cascade into other errors.

For example, if I clone the github repo: https://github.com/opencost/opencost and then open VSCode in the newly cloned directory, I immediately get the following as one of the many broken import errors:

could not import github.com/opencost/opencost/pkg/kubecost (import failed for "github.com/opencost/opencost/pkg/kubecost": internal error while importing "github.com/opencost/opencost/pkg/kubecost" (runtime error: index out of range [3142] with length 28); please report an issue)

The runtime error: index out of range [3142] with length 28 is an error I continue to see in in the problems tab for a few other imports.

I've tried:

  • go clean -cache
  • go clean -modcache
  • reinstalling the go tools

A clear and concise description of what you expected to happen.

Steps to reproduce the behavior:

  1. Clone repo https://github.com/opencost/opencost
  2. Open Repo in VS Code
  3. Note Broken Imports Errors with runtime error: index out of range [X] with length Y

Screenshots or recordings

If applicable, add screenshots or recordings to help explain your problem.

gopls-bug.mp4

(Sorry for low quality - had to keep it under 10mb 😄)

@gopherbot gopherbot added this to the Untriaged milestone Aug 1, 2023
@mbolt35
Copy link
Author

mbolt35 commented Aug 1, 2023

Note: After rolling back to gopls v0.12.4, I no longer see the broken imports errors. I did this by running:

go install golang.org/x/tools/[email protected]

and then in VS Code, Ctrl/Cmd+Shift + P -> "Go: Restart Language Server"

@findleyr
Copy link
Member

findleyr commented Aug 1, 2023

Thanks for the report. This is golang/go#61670, which is fixed in v0.13.1-pre.1. We'll release v0.13.1 later today.

In the meantime:

go install golang.org/x/tools/[email protected]

Sorry for the breakage.

@mbolt35
Copy link
Author

mbolt35 commented Aug 1, 2023

@findleyr Thank you for the info, that definitely fixes my issues. Much appreciated!

@findleyr
Copy link
Member

findleyr commented Aug 1, 2023

This should now be fixed with the v0.13.1 release.

@findleyr findleyr closed this as completed Aug 1, 2023
@golang golang locked and limited conversation to collaborators Jul 31, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants