{"record":{"id":"8e7a7309c5ec6189","repo":"gohugoio/hugo","slug":"failed-to-list-modules-w","errorCode":null,"errorMessage":"failed to list modules: %w","messagePattern":"failed to list modules: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"modules/client.go","lineNumber":530,"sourceCode":"\t\t}\n\t\treturn nil\n\t}\n\n\tif err := downloadModules(); err != nil {\n\t\treturn nil, err\n\t}\n\n\tlistAndDecodeModules := func(handle func(m *goModule) error, modules ...string) error {\n\t\tb := &bytes.Buffer{}\n\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}","sourceCodeStart":512,"sourceCodeEnd":548,"githubUrl":"https://github.com/gohugoio/hugo/blob/52c9bd7908b4d02d4d0ff8f82a888834d6ee10d2/modules/client.go#L512-L548","documentation":"listAndDecodeModules runs `go list -m -json [all]` to enumerate the resolved module graph; if that command exits non-zero, this wraps the failure. `go list` is how Hugo learns each module's Dir/Version/Replace, so a failure here means Hugo cannot construct the module set at all.","triggerScenarios":"Any module-enabled project where `go list -m -json all` fails — unresolved imports, replace directives pointing at missing local paths, go.mod syntax errors, or a go.sum missing entries that list requires.","commonSituations":"A `replace` directive in go.mod pointing to a directory that was deleted/moved, a module import path typo that go list cannot resolve, inconsistent go.mod after a merge, or GOFLAGS=-mod=vendor with a stale vendor/ dir.","solutions":["Run `go list -m all` from the project root to see the exact go-side error.","Check go.mod `replace` directives point at existing local paths; fix or remove stale ones.","Run `hugo mod tidy` to reconcile go.mod/go.sum with the actual graph.","If vendoring, regenerate the vendor dir: `hugo mod vendor` and ensure GOFLAGS is consistent."],"exampleFix":"// before: replace target deleted\nrequire github.com/x/y v1.0.0\nreplace github.com/x/y => ../y-old\n// after: remove or repoint the replace, then\nhugo mod tidy","handlingStrategy":"validation","validationCode":"// Validate the module graph resolves before Hugo\nfunc ensureModuleList(projectDir string) error {\n  cmd := exec.Command(\"go\", \"list\", \"-m\", \"all\")\n  cmd.Dir = projectDir\n  if out, err := cmd.CombinedOutput(); err != nil {\n    return fmt.Errorf(\"go list -m all: %s\", out)\n  }\n  return nil\n}","typeGuard":"null","tryCatchPattern":"null","preventionTips":["Keep replace directives pointing at existing paths.","Run `hugo mod tidy` after merging branches that touch go.mod.","Validate go.mod with `go mod verify` in CI.","Avoid mixing vendored and non-vendored layouts."],"tags":["modules","go-toolchain","hugo-module"],"backgroundTag":null,"analyzedSha":"52c9bd7908b4d02d4d0ff8f82a888834d6ee10d2","analyzedAt":"2026-08-09T21:49:36.660Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}