golang/go

cmd/go, x/mod: "invalid go version" message mentions old version format

dominikh opened this issue ยท 22 comments

When parsing an invalid go line in a go.mod, the error message says

go: errors parsing go.mod:
go.mod:3: invalid go version '1.22foo': must match format 1.23

but that's not strictly true, it doesn't have to match the 1.23 format anymore.

What version of the go CLI was this with? I've hit this this morning when using gopls that's been compiled with a pre-1.21 go. The solution was to upgrade go.

just came across this, to update vscode go tooling:

  1. Press Ctrl+Shift+P
  2. Select Go: Install/Update tools

or just to update golang language server:

go install golang.org/x/tools/gopls@latest

and you may Ctrl+Shift+P to restart language server

Change https://go.dev/cl/527897 mentions this issue: modfile: use new go version string format in error message

I just got this error message recently after I updated go. I updated gopls as well and that did not fix it. For now I've manually edited the version number to be 1.21 rather than 1.21.1

I am also noticing this occurring in newly go mod init'd projects on fresh pull of gopls@latest. Manually editing the go version in go.mod allows the language server to restart without error. I'm using vim-go which utilizes YouCompleteMe for the LSP communication to gopls.

go version                                                                                             
go version go1.21.0 linux/amd64

gopls version                                                                                         
golang.org/x/tools/gopls v0.13.2
    golang.org/x/tools/gopls@v0.13.2 h1:Pyvx6MKvatbX3zzZmdGiFRfQZl0ohPlt2sFxO/5j6Ro=

I am also running into this. Similar setup to @optik-aper:

go version go1.21.1 linux/amd64
golang.org/x/tools/gopls v0.13.2
    golang.org/x/tools/gopls@v0.13.2 h1:Pyvx6MKvatbX3zzZmdGiFRfQZl0ohPlt2sFxO/5j6Ro=

Possibly related to #63370?
There seems to be confusion to what version numbers the tools should support. Part of the challenge of introducing a new format and requiring it in the same release I think?

let4be commented

For me fixing version in go.mod and go.work to 1.21 didn't resolve the issue :(
What am I missing?

let4be commented

Hrm... should do this for all other modules in a workspace as well
Okay, changing all stuff to 1.21 resolved the issue

Is there currenlt no way to specify the version exactly, like 1.21.3?

Is this related to #62584?

I'm also getting this error, using:

go version    
go version go1.21.5 darwin/arm64

gopls version
golang.org/x/tools/gopls v0.11.0
    golang.org/x/tools/gopls@v0.11.0 h1:/nvKHdTtePQmrv9XN3gIUN9MOdUrKzO/dcqgbG6x8EY=

Previously I'd get around it by editing the go.mod file and removing the patch version, for example by changing go 1.21.4 to go 1.21 and that still works if the the mod file doesn't use replace if it does, then I get:

updates to go.mod needed, disabled by -mod=readonly; to update it: ^Igo mod tidy

To get it working I have to:

  • edit the go.mod file to remove the patch version, for example by changing go 1.21.4 to go 1.21
  • run go work init . .
  • edit the go.work file to remove the patch version, for example by changing go 1.21.5 to go 1.21

but why? why is all this needed? why are the patch versions being added to the mod files?

I'm also getting this error, using:

go version    
go version go1.21.5 darwin/arm64

gopls version
golang.org/x/tools/gopls v0.11.0
    golang.org/x/tools/gopls@v0.11.0 h1:/nvKHdTtePQmrv9XN3gIUN9MOdUrKzO/dcqgbG6x8EY=

Previously I'd get around it by editing the go.mod file and removing the patch version, for example by changing go 1.21.4 to go 1.21 and that still works if the the mod file doesn't use replace if it does, then I get:

updates to go.mod needed, disabled by -mod=readonly; to update it: ^Igo mod tidy

To get it working I have to:

* edit the `go.mod` file to remove the patch version, for example by changing `go 1.21.4` to `go 1.21`

* run `go work init . .`

* edit the `go.work` file to remove the patch version, for example by changing `go 1.21.5` to `go 1.21`

but why? why is all this needed? why are the patch versions being added to the mod files?

Also getting this at 1.21.5.
Had to move to 1.21

Looks like this was partially fixed in x/mod in https://go.dev/cl/527897, but we missed the ones in WorkFile.add:
https://cs.opensource.google/go/x/mod/+/master:modfile/rule.go;l=633-649;drc=6e58e47c7bd6672665dc35cce7b1f325d2addd67

๐Ÿคฆโ€โ™‚๏ธ

Change https://go.dev/cl/560855 mentions this issue: use new go version string format in WorkFile.add error

Change https://go.dev/cl/560855 mentions this issue: use new go version string format in WorkFile.add error message

Change https://go.dev/cl/560875 mentions this issue: use new go version string format in WorkFile.add error

I think this is fixed as of https://go.dev/cl/560855.

@bcmills can we backport this CL to 1.21 and 1.22?

https://github.com/hashicorp/terraform using go1.21.5

@maxmeng-hw, the only change for this issue was to an error message. That does not seem worth backporting, especially given that the changes are in the vendored x/mod packages (which makes them more complicated to backport).

just came across this, to update vscode go tooling:

  1. Press Ctrl+Shift+P
  2. Select Go: Install/Update tools

or just to update golang language server:

go install golang.org/x/tools/gopls@latest

and you may Ctrl+Shift+P to restart language server

After doing the steps above , you sometimes have to manually close and reopen vscode (even Ctrl+Shift+P then 'Reload Window' doesnt worked for me )