diff --git a/cmd/godoc/godoc_test.go b/cmd/godoc/godoc_test.go index 7e44348919..e61432f212 100644 --- a/cmd/godoc/godoc_test.go +++ b/cmd/godoc/godoc_test.go @@ -473,7 +473,7 @@ func TestNoMainModule(t *testing.T) { cmd.Stderr = &stderr err = cmd.Run() if err != nil { - t.Fatal(err) + t.Fatalf("godoc command failed: %v\nstderr=%q", err, stderr.String()) } if strings.Contains(stderr.String(), "go mod download") { t.Errorf("stderr contains 'go mod download', is that intentional?\nstderr=%q", stderr.String()) diff --git a/cmd/godoc/main.go b/cmd/godoc/main.go index dc8a08159f..77a38ac6f7 100644 --- a/cmd/godoc/main.go +++ b/cmd/godoc/main.go @@ -222,7 +222,7 @@ func main() { fillModuleCache(os.Stderr, goModFile) // Determine modules in the build list. - mods, err := buildList() + mods, err := buildList(goModFile) if err != nil { fmt.Fprintf(os.Stderr, "failed to determine the build list of the main module: %v", err) os.Exit(1) @@ -456,7 +456,12 @@ func fillModuleCache(w io.Writer, goMod string) { // in module mode. // // See https://golang.org/cmd/go/#hdr-The_main_module_and_the_build_list. -func buildList() ([]mod, error) { +func buildList(goMod string) ([]mod, error) { + if goMod == os.DevNull { + // Empty build list. + return nil, nil + } + out, err := exec.Command("go", "list", "-m", "-json", "all").Output() if ee := (*exec.ExitError)(nil); xerrors.As(err, &ee) { return nil, fmt.Errorf("go command exited unsuccessfully: %v\n%s", ee.ProcessState.String(), ee.Stderr)