]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/go: link to go.dev/doc/godebug for removed GODEBUG settings
authorMateusz Poliwczak <mpoliwczak34@gmail.com>
Mon, 8 Sep 2025 17:54:21 +0000 (19:54 +0200)
committerGopher Robot <gobot@golang.org>
Mon, 3 Nov 2025 21:12:15 +0000 (13:12 -0800)
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>
src/cmd/go/internal/modload/init.go
src/cmd/go/testdata/script/mod_removed_godebug.txt [new file with mode: 0644]
src/internal/godebugs/godebugs_test.go
src/internal/godebugs/table.go

index a8a72b9ad8d69b7e34a5dd1d6695189f43a966b6..3d6f9a4a65abc3c5f5f75032ac1c6a0a6c45b896 100644 (file)
@@ -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 (file)
index 0000000..bd1f61c
--- /dev/null
@@ -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
index 168acc134aa753737e863e215de44813f1fcb062..e242f58c5536c8b58884e2c99442c204e884232b 100644 (file)
@@ -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)
+               }
+       }
+}
index 852305e8553aab4069d58efc250ad743604e15f9..271c58648dc2cd0395818dea0f25ba2cbfbe5952 100644 (file)
@@ -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.