{"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/8a468df065a75c1c7cf9f6850f32148746590ea5/modules/client.go#L512-L548","documentation":"Returned when `go list -m -json all` (or for specific modules) fails while Hugo enumerates the module graph. Hugo relies on this listing to map imports to on-disk directories; failure means the module graph can't be built.","triggerScenarios":"`go list -m -json [all|mods...]` exiting non-zero: inconsistent go.mod (missing requires), Go workspace/GOFLAGS interference, missing go.sum entries with GOFLAGS=-mod=readonly, or a go version that can't parse the go.mod go directive.","commonSituations":"Hand-edited go.mod, a go.work file in a parent directory pulling the site into an unrelated workspace, Go upgraded/downgraded between builds.","solutions":["Run `hugo mod tidy` to repair go.mod/go.sum.","Run `go list -m -json all` manually in the site dir to see the raw error.","Set GOWORK=off or remove a stray go.work affecting the site directory.","Ensure the installed Go version satisfies the go directive in go.mod."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"// ensure a module file exists so 'go list -m' has something to list\nif _, err := os.Stat(filepath.Join(workingDir, \"go.mod\")); errors.Is(err, os.ErrNotExist) {\n    // run Init first or skip module listing\n}","typeGuard":null,"tryCatchPattern":"mods, err := client.List()\nif err != nil {\n    return fmt.Errorf(\"listing modules failed; verify go.mod is valid ('go mod verify'): %w\", err)\n}","preventionTips":["Ensure go.mod exists and parses before invoking list operations","Keep go.sum in sync (run 'hugo mod tidy' after editing module config)","Don't hand-edit go.mod entries to versions that don't exist"],"tags":["go-modules","hugo-mod","go-list","config"],"analyzedSha":"8a468df065a75c1c7cf9f6850f32148746590ea5","analyzedAt":"2026-07-31T21:23:07.045Z","schemaVersion":2}