{"record":{"id":"46fab814aee24f28","repo":"gohugoio/hugo","slug":"failed-to-decode-modules-list-w","errorCode":null,"errorMessage":"failed to decode modules list: %w","messagePattern":"failed to decode modules list: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"modules/client.go","lineNumber":540,"sourceCode":"\t\targs := []string{\"list\", \"-m\", \"-json\"}\n\t\tif len(modules) > 0 {\n\t\t\targs = append(args, modules...)\n\t\t} else {\n\t\t\targs = append(args, \"all\")\n\t\t}\n\t\terr := c.runGo(context.Background(), b, args...)\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"failed to list modules: %w\", err)\n\t\t}\n\n\t\tdec := json.NewDecoder(b)\n\t\tfor {\n\t\t\tm := &goModule{}\n\t\t\tif err := dec.Decode(m); err != nil {\n\t\t\t\tif err == io.EOF {\n\t\t\t\t\tbreak\n\t\t\t\t}\n\t\t\t\treturn fmt.Errorf(\"failed to decode modules list: %w\", err)\n\t\t\t}\n\n\t\t\tif err := handle(m); err != nil {\n\t\t\t\treturn err\n\t\t\t}\n\t\t}\n\t\treturn nil\n\t}\n\n\tvar modules goModules\n\terr := listAndDecodeModules(func(m *goModule) error {\n\t\tmodules = append(modules, m)\n\t\treturn nil\n\t})\n\tif err != nil {\n\t\treturn nil, err\n\t}\n","sourceCodeStart":522,"sourceCodeEnd":558,"githubUrl":"https://github.com/gohugoio/hugo/blob/52c9bd7908b4d02d4d0ff8f82a888834d6ee10d2/modules/client.go#L522-L558","documentation":"While streaming `go list -m -json all` output through a json.Decoder loop, a Decode call failed with a non-EOF error. Each module is a separate JSON object, so malformed/truncated output mid-stream trips this. Indicates corrupted or unexpected output from the go toolchain rather than a config issue.","triggerScenarios":"go list emitted partially-valid JSON then garbage — interleaved log output, killed process truncating the stream, encoding/whitespace corruption, or a Go version whose list -json shape diverges from what the decoder tolerates.","commonSituations":"Go wrapper (asdf/gvm) printing to stdout, CI log injection, OOM-killed go process mid-list, or a mismatched ancient Go binary.","solutions":["Run `go list -m -json all` manually and pipe to `jq` to find where the JSON breaks.","Ensure no shell rc / Go version manager writes to stdout during go invocation.","Upgrade/downgrade Go to a version compatible with your Hugo release.","Clear caches (`go clean -modcache`) and retry to rule out cache corruption."],"exampleFix":"// find the malformed frame\ngo list -m -json all > /tmp/list.json\njq -c '.' /tmp/list.json   // reports the first bad object","handlingStrategy":"validation","validationCode":"// Ensure list output is clean JSON\nfunc ensureListJSON(projectDir string) error {\n  cmd := exec.Command(\"go\", \"list\", \"-m\", \"-json\", \"all\")\n  cmd.Dir = projectDir\n  out, err := cmd.Output()\n  if err != nil { return err }\n  dec := json.NewDecoder(bytes.NewReader(out))\n  for {\n    var m map[string]any\n    if err := dec.Decode(&m); err != nil {\n      if err == io.EOF { return nil }\n      return err\n    }\n  }\n}","typeGuard":"null","tryCatchPattern":"null","preventionTips":["Don't let tools/version-managers write to stdout during go.","Use a Go version compatible with your Hugo release.","Clear the module cache on suspected corruption."],"tags":["modules","go-toolchain","json","hugo-module"],"backgroundTag":null,"analyzedSha":"52c9bd7908b4d02d4d0ff8f82a888834d6ee10d2","analyzedAt":"2026-08-09T21:49:36.660Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}