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

doc: clarify that godebug in go.mod is ignored when using a workspace in favor of go.work's godebug #72109

Closed
pgimalac opened this issue Mar 5, 2025 · 4 comments
Assignees
Labels
BugReport Issues describing a possible bug in the Go implementation. Documentation Issues describing a change to documentation. FixPending Issues that have a fix which has not yet been reviewed or submitted. GoCommand cmd/go NeedsFix The path to resolution is known, but the work has not been done.
Milestone

Comments

@pgimalac
Copy link

pgimalac commented Mar 5, 2025

Go version

1.23.6 and 1.24.0

Output of go env in your module/workspace:

AR='ar'
CC='clang'
CGO_CFLAGS='-O2 -g'
CGO_CPPFLAGS=''
CGO_CXXFLAGS='-O2 -g'
CGO_ENABLED='1'
CGO_FFLAGS='-O2 -g'
CGO_LDFLAGS='-O2 -g'
CXX='clang++'
GCCGO='gccgo'
GO111MODULE='auto'
GOARCH='arm64'
GOARM64='v8.0'
GOAUTH='netrc'
GOBIN=''
GOCACHE='/Users/pierre.gimalac/Library/Caches/go-build'
GOCACHEPROG=''
GODEBUG=''
GOENV='/Users/pierre.gimalac/Library/Application Support/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFIPS140='off'
GOFLAGS=''
GOGCCFLAGS='-fPIC -arch arm64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -ffile-prefix-map=/var/folders/zp/m8h1x16s30g3f656sxsdt7rm0000gp/T/go-build4235974089=/tmp/go-build -gno-record-gcc-switches -fno-common'
GOHOSTARCH='arm64'
GOHOSTOS='darwin'
GOINSECURE=''
GOMOD='/tmp/iy4pULX4rXgOq5Il/go.mod'
GOMODCACHE='/Users/pierre.gimalac/go/pkg/mod'
GONOPROXY='github.com/DataDog'
GONOSUMDB='github.com/DataDog,go.ddbuild.io'
GOOS='darwin'
GOPATH='/Users/pierre.gimalac/go'
GOPRIVATE='github.com/DataDog'
GOPROXY='binaries.ddbuild.io,proxy.golang.org,direct'
GOROOT='/usr/local/go'
GOSUMDB='sum.golang.org'
GOTELEMETRY='local'
GOTELEMETRYDIR='/Users/pierre.gimalac/Library/Application Support/go/telemetry'
GOTMPDIR=''
GOTOOLCHAIN='auto'
GOTOOLDIR='/usr/local/go/pkg/tool/darwin_arm64'
GOVCS=''
GOVERSION='go1.24.0'
GOWORK='/tmp/iy4pULX4rXgOq5Il/go.work'
PKG_CONFIG='pkg-config'

What did you do?

The godebug directives in the go.mod file of the main package are ignored when using a workspace.

I'm not sure if this is a bug or on purpose, but if it's on purpose I feel like it should be clearer in the documentation, and possibly warned explicitly when running a go command.

The following piece of sentence appears twice in the documentation https://go.dev/doc/godebug, but it's not clear to me that go.mod is ignored when using a go.work.

[...] the work module’s go.mod or the workspace’s go.work [...]

Reproducible example

Consider the following main.go, it prints the value of the godebug setting panicnil.

package main

import "fmt"

func main() {
	defer func() {
		if r := recover(); r != nil {
			fmt.Println("panicnil=0")
		} else {
			fmt.Println("panicnil=1")
		}
	}()
	panic(nil)
}

Create a go.mod file with a godebug directive for panicnil:

module mytest

go 1.23.6

godebug panicnil=1

And a go.work without said directive:

go 1.23.6

use .

Then run the code with and without workspace:

$ go run main.go
panicnil=0
$ GOWORK=off go run main.go
panicnil=1

The directive in the go.mod file is ignored when using a workspace.

Alternatively using go list also shows the diff:

$ go list -f '{{.DefaultGODEBUG}}'
$ GOWORK=off go list -f '{{.DefaultGODEBUG}}'
panicnil=1

What did you see happen?

The directive in the go.mod file is ignored when using a workspace.

What did you expect to see?

I expected the godebug directive in the go.mod to be used, or in the worst case scenario a warning about it being ignored due to using a workspace.
(or even just improve the documentation to make this case clear)

@pgimalac
Copy link
Author

pgimalac commented Mar 5, 2025

Ah very good bot, the "related documentation" https://go.dev/ref/mod#go-work-file-godebug does say

When a workspace is in use, godebug directives in go.mod files are ignored.

Should the other doc https://go.dev/doc/godebug be updated to reflect this too ?

@gabyhelp gabyhelp added the BugReport Issues describing a possible bug in the Go implementation. label Mar 5, 2025
@dmitshur dmitshur changed the title godebug: directive is ignored in go.mod when using a workspace cmd/go: godebug directive is ignored in go.mod when using a workspace Mar 5, 2025
@dmitshur dmitshur added the GoCommand cmd/go label Mar 5, 2025
@ianlancetaylor
Copy link
Member

CC @matloob @samthanawalla

@matloob matloob self-assigned this Mar 5, 2025
@matloob matloob changed the title cmd/go: godebug directive is ignored in go.mod when using a workspace doc: clarify that godebug in go.mod is ignored when using a workspace in favor of go.work's godebug Mar 5, 2025
@gopherbot gopherbot added the Documentation Issues describing a change to documentation. label Mar 5, 2025
@gopherbot
Copy link
Contributor

Change https://go.dev/cl/655158 mentions this issue: doc: update godebug doc to clarify godebug directive in workspace

@dmitshur dmitshur added NeedsFix The path to resolution is known, but the work has not been done. FixPending Issues that have a fix which has not yet been reviewed or submitted. labels Mar 5, 2025
@dmitshur dmitshur added this to the Go1.25 milestone Mar 5, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
BugReport Issues describing a possible bug in the Go implementation. Documentation Issues describing a change to documentation. FixPending Issues that have a fix which has not yet been reviewed or submitted. GoCommand cmd/go NeedsFix The path to resolution is known, but the work has not been done.
Projects
None yet
Development

No branches or pull requests

6 participants