You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
dagger mod init fails with confusing error message when there is already a go.mod #6329
go mod init github.com/samalba/sandbox/test
dagger mod init --name=test --sdk=go
Output
✘ generatedCode ERROR [0.57s]
✘ exec /usr/local/bin/codegen --module . --propagate-logs=true --introspection-json-path /schema.json ERROR [0.34s]
┃ Error: load package ".": err: exit status 1: stderr: go: go.mod requires go >= 1.21.5 (running go 1.21.3; GOTOOLCHAIN=local)
✘ generating go module: test ERROR [0.04s]
├ [0.00s] go mod tidy
┃ writing dagger.gen.go
┃ writing go.mod
┃ writing go.sum
┃ writing main.go
┃ creating directory querybuilder
┃ writing querybuilder/marshal.go
┃ writing querybuilder/querybuilder.go
┃ go: go.mod requires go >= 1.21.5 (running go 1.21.3; GOTOOLCHAIN=local)
┃ needs another pass...
• Cloud URL: https://dagger.cloud/runs/0bafbb50-94f4-49e4-8cfc-3e8f28582770
• Engine: 580198e00e2f (version v0.9.5)
⧗ 1.70s ✔ 18 ∅ 2 ✘ 3
Error: failed to automate vcs: failed to get vcs ignored paths: input:1: host.directory.asModule.generatedCode failed to get modified source directory for go module sdk codegen: process "/usr/local/bin/codegen --module . --propagate-logs=true --introspection-json-path /schema.json" did not complete successfully: exit code: 1
Info
dagger 0.9.5 go 1.21.5
Expected behavior
It's normal to fail when a go mod already exists, however the error is confusing and useless. go.mod requires go >= 1.21.5 -> I am already using 1.21.5
Instead, a message saying something like: cannot initialize dagger module: a go module already exists.
@samalba To clarify, you are allowed to have an existing go.mod and that's handled in general (there's integ test coverage for this). The problem here is that Go in 1.21 started creating go.mod by default with directives like go 1.21.5 which result in these errors if there's a mismatch between the version of go being used by the engine the and the version of go you used to run go mod init on your host.
So you don't get this error if your host is using go 1.21.3 (what the engine is currently on).
You can easily fix this right now by just editing the go.mod created by go mod init to just say go 1.21 rather than go 1.21.5.
I'm sure there's got to be some better way of handling this in general since there's no way we actually care about the patch version of Go.
Thanks for the context. Maybe a good way to solve this is to detect if there is a minor version in go.mod and hint the user to remove it. If I learned this from the output, I would have done this manually to fix it.
As a note, Nipuna mentioned that he also needed to make the same adjustment to his go.work file to remove the minor version in order for this to work fully
Hi, I had a look at this issue, and found out that it only happens if you run go mod init before dagger mod init, and if you have go > 1.21.3 locally. because go mod init will create a go.mod file with your local version of go (say 1.21.5), but when running dagger mod init, it will run in a container with go 1.21.3 in local mode, so it won't be able to do anything
the "quick" fix is to avoid running go mod init, because dagger mod init will take care of creating the go.mod file anyway if it doesn't exists, and it will have the "right" go version (the one used by the dagger container)
the real fix is to ensure that the container is properly configured, with GOTOOLCHAIN=auto. by default, the official go images have GOTOOLCHAIN=local, which is ok because you want a controlled env. but in the dagger context, I believe it makes sense to be able to run the code if even it requires a newer version of go. just adding the GOTOOLCHAIN=auto env to the container will do it:
$ echo$(docker run --rm -it golang:1.21.3 go env GOTOOLCHAIN)local
$ echo$(docker run --rm -it -e GOTOOLCHAIN=auto golang:1.21.3 go env GOTOOLCHAIN)
auto
This is no longer relevant because for a while now, the Go SDK's codegen merges the new modules go.mod with the existing one, so no longer returns an error.
Activity
sipsma commentedon Jan 2, 2024
@samalba To clarify, you are allowed to have an existing go.mod and that's handled in general (there's integ test coverage for this). The problem here is that Go in 1.21 started creating
go.modby default with directives likego 1.21.5which result in these errors if there's a mismatch between the version of go being used by the engine the and the version of go you used to rungo mod initon your host.So you don't get this error if your host is using go 1.21.3 (what the engine is currently on).
You can easily fix this right now by just editing the
go.modcreated bygo mod initto just saygo 1.21rather thango 1.21.5.I'm sure there's got to be some better way of handling this in general since there's no way we actually care about the patch version of Go.
samalba commentedon Jan 4, 2024
Thanks for the context. Maybe a good way to solve this is to detect if there is a minor version in go.mod and hint the user to remove it. If I learned this from the output, I would have done this manually to fix it.
sipsma commentedon Jan 10, 2024
As a note, Nipuna mentioned that he also needed to make the same adjustment to his
go.workfile to remove the minor version in order for this to work fullyvbehar commentedon Jan 12, 2024
Hi, I had a look at this issue, and found out that it only happens if you run
go mod initbeforedagger mod init, and if you have go > 1.21.3 locally. becausego mod initwill create ago.modfile with your local version of go (say 1.21.5), but when runningdagger mod init, it will run in a container with go 1.21.3 inlocalmode, so it won't be able to do anythingthe "quick" fix is to avoid running
go mod init, becausedagger mod initwill take care of creating thego.modfile anyway if it doesn't exists, and it will have the "right" go version (the one used by the dagger container)the real fix is to ensure that the container is properly configured, with
GOTOOLCHAIN=auto. by default, the official go images haveGOTOOLCHAIN=local, which is ok because you want a controlled env. but in the dagger context, I believe it makes sense to be able to run the code if even it requires a newer version of go. just adding theGOTOOLCHAIN=autoenv to the container will do it:helderco commentedon Aug 1, 2024
This is no longer relevant because for a while now, the Go SDK's codegen merges the new modules
go.modwith the existing one, so no longer returns an error.