diff --git a/dev-tools/mage/gotool/go.go b/dev-tools/mage/gotool/go.go index bb7066a4f3e5..e507282c15ce 100644 --- a/dev-tools/mage/gotool/go.go +++ b/dev-tools/mage/gotool/go.go @@ -58,12 +58,19 @@ var Test goTest = runGoTest // GetModuleName returns the name of the module. func GetModuleName() (string, error) { - lines, err := getLines(callGo(nil, "list", "-m")) + lines, err := getLines(callGo( + // Disabling the Go workspace prevents 'go list' from listing all + // modules within the workspace. + map[string]string{"GOWORK": "off"}, + "list", + "-m")) if err != nil { return "", err } + if len(lines) != 1 { - return "", fmt.Errorf("unexpected number of lines") + return "", fmt.Errorf("expected 'go list -m' to return 1 line, got %d", + len(lines)) } return lines[0], nil }