{"record":{"id":"0014a4df4f25447a","repo":"golang/go","slug":"unexpected-stdout-q","errorCode":null,"errorMessage":"unexpected stdout: %q","messagePattern":"unexpected stdout: %q","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/cmd/go/internal/doc/dirs.go","lineNumber":306,"sourceCode":"\n// getMainModuleAnd114 gets the main module's information and whether the\n// go command in use is 1.14+. This is the information needed to figure out\n// if vendoring should be enabled.\nfunc getMainModuleAnd114() (*moduleJSON, bool, error) {\n\tconst format = `{{.Path}}\n{{.Dir}}\n{{.GoVersion}}\n{{range context.ReleaseTags}}{{if eq . \"go1.14\"}}{{.}}{{end}}{{end}}\n`\n\tcmd := exec.Command(goCmd(), \"list\", \"-m\", \"-f\", format)\n\tcmd.Stderr = os.Stderr\n\tstdout, err := cmd.Output()\n\tif err != nil {\n\t\treturn nil, false, nil\n\t}\n\tlines := strings.Split(string(stdout), \"\\n\")\n\tif len(lines) < 5 {\n\t\treturn nil, false, fmt.Errorf(\"unexpected stdout: %q\", stdout)\n\t}\n\tmod := &moduleJSON{\n\t\tPath:      lines[0],\n\t\tDir:       lines[1],\n\t\tGoVersion: lines[2],\n\t}\n\treturn mod, lines[3] == \"go1.14\", nil\n}\n","sourceCodeStart":288,"sourceCodeEnd":315,"githubUrl":"https://github.com/golang/go/blob/b6b368adc57c96c3151d224d172029f233ead2c3/src/cmd/go/internal/doc/dirs.go#L288-L315","documentation":"Returned by the doc/dirs module-info probe when `go list -m -f <format>` produces fewer than 5 lines of stdout. The fixed template emits Path/Dir/GoVersion plus two trailing lines, so a short output means the module listing did not match the expected shape — usually because there is no module, the go command is the wrong version, or list failed silently (stderr already printed).","triggerScenarios":"Running go doc's module probe in a directory with no go.mod; with an old/new go version whose `go list -m` output differs; when go list exits 0 but emits only a partial block. The code path checks `len(lines) < 5` after splitting on newlines.","commonSituations":"GOPATH-mode projects (no module); mixed Go toolchain versions; corrupted module state; go list hitting an internal error that still returns 0.","solutions":["Ensure you are inside a module (`go mod init` if needed) or upgrade the project to modules.","Run `go list -m` manually to see what it emits and fix the underlying module state.","Run `go mod tidy` to repair module metadata.","Confirm the go toolchain version matches what the project expects."],"exampleFix":"# before: no go.mod in the tree\n$ go doc ./...\n# -> unexpected stdout\n\n# after\n$ go mod init example.com/mymodule\n$ go doc ./...","handlingStrategy":"validation","validationCode":"// before relying on the module probe, confirm a module exists\nif _, err := os.Stat(\"go.mod\"); err != nil {\n    return errors.New(\"no go.mod: initialize a module first\")\n}","typeGuard":null,"tryCatchPattern":"mod, ok, err := dirs.ModuleInfo(ctx)\nif err != nil && strings.Contains(err.Error(), \"unexpected stdout\") {\n    // run `go list -m` to surface the real cause, then retry\n    _ = runShell(\"go\", \"list\", \"-m\")\n}","preventionTips":["Keep projects on modules (go.mod present).","Pin a single Go toolchain version in CI.","Run `go list -m` during onboarding to verify module state."],"tags":["doc","module","parsing","go-list"],"analyzedSha":"b6b368adc57c96c3151d224d172029f233ead2c3","analyzedAt":"2026-08-12T00:22:02.250Z","schemaVersion":2},"datasetVersion":"2026-08-12T06:17:24.410Z"}