Skip to content

Commit aa94fdf

Browse files
mateusz834gopherbot
authored andcommitted
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>
1 parent 4d2b03d commit aa94fdf

File tree

4 files changed

+35
-3
lines changed

4 files changed

+35
-3
lines changed

src/cmd/go/internal/modload/init.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2242,9 +2242,12 @@ func CheckGodebug(verb, k, v string) error {
22422242
}
22432243
return nil
22442244
}
2245-
for _, info := range godebugs.All {
2246-
if k == info.Name {
2247-
return nil
2245+
if godebugs.Lookup(k) != nil {
2246+
return nil
2247+
}
2248+
for _, info := range godebugs.Removed {
2249+
if info.Name == k {
2250+
return fmt.Errorf("use of removed %s %q, see https://go.dev/doc/godebug#go-1%v", verb, k, info.Removed)
22482251
}
22492252
}
22502253
return fmt.Errorf("unknown %s %q", verb, k)
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Test case that makes sure we print a nice error message
2+
# instead of the generic "unknown godebug" error message
3+
# for removed GODEBUGs.
4+
5+
! go list
6+
stderr '^go.mod:3: use of removed godebug "x509sha1", see https://go.dev/doc/godebug#go-124$'
7+
8+
-- go.mod --
9+
module example.com/bar
10+
11+
godebug x509sha1=1

src/internal/godebugs/godebugs_test.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,3 +93,11 @@ func incNonDefaults(t *testing.T) map[string]bool {
9393
}
9494
return seen
9595
}
96+
97+
func TestRemoved(t *testing.T) {
98+
for _, info := range godebugs.Removed {
99+
if godebugs.Lookup(info.Name) != nil {
100+
t.Fatalf("GODEBUG: %v exists in both Removed and All", info.Name)
101+
}
102+
}
103+
}

src/internal/godebugs/table.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,16 @@ var All = []Info{
7878
{Name: "zipinsecurepath", Package: "archive/zip"},
7979
}
8080

81+
type RemovedInfo struct {
82+
Name string // name of the removed GODEBUG setting.
83+
Removed int // minor version of Go, when the removal happened
84+
}
85+
86+
// Removed contains all GODEBUGs that we have removed.
87+
var Removed = []RemovedInfo{
88+
{Name: "x509sha1", Removed: 24},
89+
}
90+
8191
// Lookup returns the Info with the given name.
8292
func Lookup(name string) *Info {
8393
// binary search, avoiding import of sort.

0 commit comments

Comments
 (0)