From aa94fdf0cc693b5846a936d5cd6f3bd358093245 Mon Sep 17 00:00:00 2001 From: Mateusz Poliwczak Date: Mon, 8 Sep 2025 19:54:21 +0200 Subject: [PATCH] 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 LUCI-TryBot-Result: Go LUCI Auto-Submit: Mateusz Poliwczak Reviewed-by: Michael Matloob Reviewed-by: Michael Matloob --- src/cmd/go/internal/modload/init.go | 9 ++++++--- src/cmd/go/testdata/script/mod_removed_godebug.txt | 11 +++++++++++ src/internal/godebugs/godebugs_test.go | 8 ++++++++ src/internal/godebugs/table.go | 10 ++++++++++ 4 files changed, 35 insertions(+), 3 deletions(-) create mode 100644 src/cmd/go/testdata/script/mod_removed_godebug.txt diff --git a/src/cmd/go/internal/modload/init.go b/src/cmd/go/internal/modload/init.go index a8a72b9ad8..3d6f9a4a65 100644 --- a/src/cmd/go/internal/modload/init.go +++ b/src/cmd/go/internal/modload/init.go @@ -2242,9 +2242,12 @@ func CheckGodebug(verb, k, v string) error { } return nil } - for _, info := range godebugs.All { - if k == info.Name { - return nil + if godebugs.Lookup(k) != 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) diff --git a/src/cmd/go/testdata/script/mod_removed_godebug.txt b/src/cmd/go/testdata/script/mod_removed_godebug.txt new file mode 100644 index 0000000000..bd1f61c9d2 --- /dev/null +++ b/src/cmd/go/testdata/script/mod_removed_godebug.txt @@ -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 diff --git a/src/internal/godebugs/godebugs_test.go b/src/internal/godebugs/godebugs_test.go index 168acc134a..e242f58c55 100644 --- a/src/internal/godebugs/godebugs_test.go +++ b/src/internal/godebugs/godebugs_test.go @@ -93,3 +93,11 @@ func incNonDefaults(t *testing.T) map[string]bool { } 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) + } + } +} diff --git a/src/internal/godebugs/table.go b/src/internal/godebugs/table.go index 852305e855..271c58648d 100644 --- a/src/internal/godebugs/table.go +++ b/src/internal/godebugs/table.go @@ -78,6 +78,16 @@ var All = []Info{ {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. func Lookup(name string) *Info { // binary search, avoiding import of sort. -- 2.52.0