{"record":{"id":"b2af5c3fae69b769","repo":"kubernetes/kubernetes","slug":"json-unmarshal-of-go-list-failed-w","errorCode":null,"errorMessage":"json unmarshal of `go list` failed: %w","messagePattern":"json unmarshal of `go list` failed: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"hack/tools/instrumentation/main.go","lineNumber":301,"sourceCode":"\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\treturn consts\n}\n\nfunc findPkgDir(pkg string) (string, error) {\n\t// Use Go's module mechanism.\n\tcmd := exec.Command(\"go\", \"list\", \"-find\", \"-json=Dir\", pkg)\n\tout, err := cmd.CombinedOutput()\n\tif err != nil {\n\t\treturn \"\", fmt.Errorf(\"running `go list` failed: %w\\n\\n%s\", err, string(out))\n\t}\n\tresult := struct {\n\t\tDir string\n\t}{}\n\tif err := json.Unmarshal(out, &result); err != nil {\n\t\treturn \"\", fmt.Errorf(\"json unmarshal of `go list` failed: %w\", err)\n\t}\n\tif result.Dir != \"\" {\n\t\treturn result.Dir, nil\n\t}\n\n\treturn \"\", fmt.Errorf(\"empty respose from `go list`\")\n}\n\nfunc importedGlobalVariableDeclaration(localVariables map[string]ast.Expr, imports []*ast.ImportSpec) (map[string]ast.Expr, error) {\n\tfor _, im := range imports {\n\t\t// get imported label\n\t\tvar importAlias string\n\t\tif im.Name == nil {\n\t\t\tpathSegments := strings.Split(im.Path.Value, \"/\")\n\t\t\timportAlias = strings.Trim(pathSegments[len(pathSegments)-1], \"\\\"\")\n\t\t} else {\n\t\t\timportAlias = im.Name.String()\n\t\t}","sourceCodeStart":283,"sourceCodeEnd":319,"githubUrl":"https://github.com/kubernetes/kubernetes/blob/94c136764292cc5fac976c0de6587daaea56410f/hack/tools/instrumentation/main.go#L283-L319","documentation":"Returned by findPkgDir() in hack/tools/instrumentation/main.go:301 when json.Unmarshal fails parsing the JSON output of `go list`. The tool expects a JSON object with a Dir field; a parse failure means go list produced output that is not valid JSON (or not the expected shape) despite exiting zero.","triggerScenarios":"A Go toolchain version that changes the `go list -json=Dir` output format, or interleaved non-JSON log lines (e.g. build warnings printed to stdout instead of stderr) corrupting the buffer.","commonSituations":"Upgrading the Go toolchain to a version with a different go list JSON schema; GOFLAGS/verbose logging that pollutes stdout; a wrapper around `go` (e.g. a shell alias) emitting extra text.","solutions":["Run `go list -find -json=Dir <pkg>` and inspect the raw output for non-JSON lines.","Pin/align the Go toolchain version with what the repo expects (see hack/*.go-version or .go-version).","Remove any `go` wrapper/alias that adds stdout output."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"// Detect non-JSON stdout from go list before running the tool.\nout, _ := exec.Command(\"go\", \"list\", \"-find\", \"-json=Dir\", pkg).Output()\nif !json.Valid(out) { return fmt.Errorf(\"go list emits non-JSON; check toolchain/GOFLAGS\") }","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Pin the Go toolchain to the repo-required version.","Remove any `go` shell wrapper that prints to stdout."],"tags":["instrumentation","go-list","json","toolchain","kubernetes-build-tooling"],"backgroundTag":null,"analyzedSha":"94c136764292cc5fac976c0de6587daaea56410f","analyzedAt":"2026-08-08T23:58:27.554Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}