{"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/8a468df065a75c1c7cf9f6850f32148746590ea5/modules/client.go#L522-L558","documentation":"Returned when `go list -m -json` exited successfully but Hugo's streaming JSON decode of the concatenated module objects failed mid-stream. Indicates malformed or unexpected content in the list output rather than a listing failure.","triggerScenarios":"json.Decoder hitting a non-EOF error while decoding the `go list -m -json` stream: extraneous stdout output from go wrappers, warnings interleaved into stdout, or output format changes across Go versions.","commonSituations":"go binary shims that echo to stdout, GODEBUG or toolchain-switch notices landing on stdout in unusual environments, very new Go releases altering field types.","solutions":["Run `go list -m -json all` manually and check the output is pure JSON.","Remove go wrappers/aliases that print extra text.","Upgrade Hugo to a version tested against your Go release.","Unset GODEBUG/GOFLAGS entries influencing go output."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":"func isDecodeErr(err error) bool {\n    var syntaxErr *json.SyntaxError\n    return errors.As(err, &syntaxErr)\n}","tryCatchPattern":"mods, err := client.List()\nif err != nil {\n    if isDecodeErr(err) {\n        return fmt.Errorf(\"'go list -m -json' produced unparseable output; check Go toolchain version and that no wrapper pollutes stdout: %w\", err)\n    }\n    return err\n}","preventionTips":["Pin a supported Go toolchain version in CI images","Avoid shell wrappers/aliases around the go binary that print extra text to stdout","Treat decode errors as environment defects, not retryable conditions"],"tags":["go-modules","hugo-mod","json-decode","toolchain"],"analyzedSha":"8a468df065a75c1c7cf9f6850f32148746590ea5","analyzedAt":"2026-07-31T21:23:07.045Z","schemaVersion":2}