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/gopls: Upgrade check on Go 1.22 projects fails #66055

Closed
der-eismann opened this issue Mar 1, 2024 · 7 comments
Closed

x/tools/gopls: Upgrade check on Go 1.22 projects fails #66055

der-eismann opened this issue Mar 1, 2024 · 7 comments
Assignees
Labels
gopls Issues related to the Go language server, gopls. Tools This label describes issues relating to any tools in the x/tools repository.
Milestone

Comments

@der-eismann
Copy link

gopls version

v0.15.1

go env

GO111MODULE=''
GOARCH='amd64'
GOBIN=''
GOCACHE='/home/sysop/.cache/go-build'
GOENV='/home/sysop/.config/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFLAGS=''
GOHOSTARCH='amd64'
GOHOSTOS='linux'
GOINSECURE=''
GOMODCACHE='/home/sysop/go/pkg/mod'
GONOPROXY=''
GONOSUMDB=''
GOOS='linux'
GOPATH='/home/sysop/go'
GOPRIVATE=''
GOPROXY='https://proxy.golang.org,direct'
GOROOT='/var/lib/snapd/snap/go/10506'
GOSUMDB='sum.golang.org'
GOTMPDIR=''
GOTOOLCHAIN='auto'
GOTOOLDIR='/var/lib/snapd/snap/go/10506/pkg/tool/linux_amd64'
GOVCS=''
GOVERSION='go1.22.0'
GCCGO='gccgo'
GOAMD64='v1'
AR='ar'
CC='gcc'
CXX='g++'
CGO_ENABLED='1'
GOMOD='/home/sysop/rebuy/terraform-cluster-config/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 -ffile-prefix-map=/tmp/go-build3341802980=/tmp/go-build -gno-record-gcc-switches'

What did you do?

I updated a project to use Go 1.22 and set go 1.22.0 in the go.mod file. After that I pressed the Check for upgrades button in VSCode.

What did you see happen?

Error by VSCode saying:

Command 'gopls.check_upgrades' failed: Error: err: exit status 1: stderr:
  go: can't determine available upgrades using the vendor directory (Use -mod=mod or -mod=readonly to bypass.) .

My guess is that this is the root cause, as the go list -m -u -json command fails on my command prompt as well. When I add "buildFlags": ["-mod=mod"], to the gopls config in vscode, it's starting to work again.

What did you expect to see?

A running upgrade check that marks dependencies that can be updated.

Editor and settings

    "gopls": {
        // Add parameter placeholders when completing a function.
        "usePlaceholders": true,
        // If true, enable additional analyses with staticcheck.
        // Warning: This will significantly increase memory usage.
        "staticcheck": false,
    },
    "[go]": {
        "editor.formatOnSave": true,
        "editor.codeActionsOnSave": {
            "source.organizeImports": "explicit"
        },
        // Optional: Disable snippets, as they conflict with completion ranking.
        "editor.snippetSuggestions": "none",
    },
    "[go.mod]": {
        "editor.formatOnSave": true,
        "editor.codeActionsOnSave": {
            "source.organizeImports": "explicit"
        },
    },
    "[go][go.mod]": {
        "editor.codeActionsOnSave": {
            "source.organizeImports": "explicit"
        }
    },

Logs

[Error - 14:05:37] Request workspace/executeCommand failed.
  Message: err: exit status 1: stderr: go: can't determine available upgrades using the vendor directory
	(Use -mod=mod or -mod=readonly to bypass.)
@der-eismann der-eismann added gopls Issues related to the Go language server, gopls. Tools This label describes issues relating to any tools in the x/tools repository. labels Mar 1, 2024
@gopherbot gopherbot added this to the Unreleased milestone Mar 1, 2024
@adonovan
Copy link
Member

adonovan commented Mar 4, 2024

cc @findleyr

@findleyr
Copy link
Contributor

findleyr commented Mar 4, 2024

Thanks for the report. Indeed, this looks like a recent regression related to some refactoring I did in the gocommand package (we fall back to the default value for the -mod flag in more cases).

Should be straightforward to reproduce and fix, thanks to your analysis.

@findleyr findleyr self-assigned this Mar 4, 2024
@findleyr findleyr modified the milestones: Unreleased, gopls/v0.16.0 Mar 4, 2024
@alexellis
Copy link

Hi @findleyr this is affecting me and I'm unsure what to do to get around it. There's countless OSS projects I maintain in Go that need minor updates to go.mod for CVEs etc, and this is blocking for the time being?

Thanks

Alex

@findleyr
Copy link
Contributor

findleyr commented Mar 6, 2024

Hi @alexellis, I will try to prioritize this fix. It looks like we will have a gopls@v0.15.2 soon, and if feasible I'll cherry-pick this fix in as well. However, even if it misses that release you can always install gopls from master as soon as the fix lands.

@findleyr findleyr modified the milestones: gopls/v0.16.0, gopls/v0.15.2 Mar 7, 2024
@gopherbot
Copy link

Change https://go.dev/cl/569877 mentions this issue: gopls/internal/server: set -mod=readonly when checking for upgrades

@gopherbot
Copy link

Change https://go.dev/cl/569878 mentions this issue: [gopls-release-branch.0.15] gopls/internal/server: set -mod=readonly when checking for upgrades

gopherbot pushed a commit to golang/tools that referenced this issue Mar 8, 2024
…when checking for upgrades

When a vendor directory is present, we must explicitly use -mod=readonly
to query upgrades with `go list`. This was broken by the fixes for
workspace vendoring, which removed the `-mod` flag in most usage of the
gocommand package.

Fixes golang/go#66055

Change-Id: I29efb617a8fe56e9752dc088dc5ea884f1cefb86
Reviewed-on: https://go-review.googlesource.com/c/tools/+/569877
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Alan Donovan <adonovan@google.com>
(cherry picked from commit c178933)
Reviewed-on: https://go-review.googlesource.com/c/tools/+/569878
Reviewed-by: Nooras Saba‎ <saba@golang.org>
Auto-Submit: Robert Findley <rfindley@google.com>
@findleyr
Copy link
Contributor

findleyr commented Mar 8, 2024

This is fixed in the gopls prerelease:

go install golang.org/x/tools/gopls@v0.15.2-pre.1

We will likely release this early next week.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
gopls Issues related to the Go language server, gopls. Tools This label describes issues relating to any tools in the x/tools repository.
Projects
None yet
Development

No branches or pull requests

5 participants