cmd/go: link to go.dev/doc/godebug for removed GODEBUG settings

This makes the user experience better, before users would receive
an unknown godebug error message, now we explicitly mention that
it was removed and link to go.dev/doc/godebug where users can find
more information about the removal.

Additionally we keep all the removed GODEBUGs in the source, making
sure we do not reuse such GODEBUG after it is removed.

Updates #72111
Updates #75316

Change-Id: I6a6a6964cce1c100108fdba4bfba7d13cd9a893a
Reviewed-on: https://go-review.googlesource.com/c/go/+/701875
Reviewed-by: Michael Pratt <mpratt@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Auto-Submit: Mateusz Poliwczak <mpoliwczak34@gmail.com>
Reviewed-by: Michael Matloob <matloob@golang.org>
Reviewed-by: Michael Matloob <matloob@google.com>
This commit is contained in:
Mateusz Poliwczak 2025-09-08 19:54:21 +02:00 committed by Gopher Robot
parent 4d2b03d2fc
commit aa94fdf0cc
4 changed files with 35 additions and 3 deletions

View file

@ -2242,9 +2242,12 @@ func CheckGodebug(verb, k, v string) error {
} }
return nil return nil
} }
for _, info := range godebugs.All { if godebugs.Lookup(k) != nil {
if k == info.Name { return nil
return nil }
for _, info := range godebugs.Removed {
if info.Name == k {
return fmt.Errorf("use of removed %s %q, see https://go.dev/doc/godebug#go-1%v", verb, k, info.Removed)
} }
} }
return fmt.Errorf("unknown %s %q", verb, k) return fmt.Errorf("unknown %s %q", verb, k)

View file

@ -0,0 +1,11 @@
# Test case that makes sure we print a nice error message
# instead of the generic "unknown godebug" error message
# for removed GODEBUGs.
! go list
stderr '^go.mod:3: use of removed godebug "x509sha1", see https://go.dev/doc/godebug#go-124$'
-- go.mod --
module example.com/bar
godebug x509sha1=1

View file

@ -93,3 +93,11 @@ func incNonDefaults(t *testing.T) map[string]bool {
} }
return seen return seen
} }
func TestRemoved(t *testing.T) {
for _, info := range godebugs.Removed {
if godebugs.Lookup(info.Name) != nil {
t.Fatalf("GODEBUG: %v exists in both Removed and All", info.Name)
}
}
}

View file

@ -78,6 +78,16 @@ var All = []Info{
{Name: "zipinsecurepath", Package: "archive/zip"}, {Name: "zipinsecurepath", Package: "archive/zip"},
} }
type RemovedInfo struct {
Name string // name of the removed GODEBUG setting.
Removed int // minor version of Go, when the removal happened
}
// Removed contains all GODEBUGs that we have removed.
var Removed = []RemovedInfo{
{Name: "x509sha1", Removed: 24},
}
// Lookup returns the Info with the given name. // Lookup returns the Info with the given name.
func Lookup(name string) *Info { func Lookup(name string) *Info {
// binary search, avoiding import of sort. // binary search, avoiding import of sort.