{"record":{"id":"1a1156bd1422a738","repo":"gohugoio/hugo","slug":"failed-to-init-modules-w","errorCode":null,"errorMessage":"failed to init modules: %w","messagePattern":"failed to init modules: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"modules/client.go","lineNumber":369,"sourceCode":"\t}\n\n\treturn c.get(args...)\n}\n\nfunc (c *Client) get(args ...string) error {\n\tif err := c.runGo(context.Background(), c.logger.StdOut(), append([]string{\"get\"}, args...)...); err != nil {\n\t\treturn fmt.Errorf(\"failed to get %q: %w\", args, err)\n\t}\n\treturn nil\n}\n\n// Init initializes this as a Go Module with the given path.\n// If path is empty, Go will try to guess.\n// If this succeeds, this project will be marked as Go Module.\nfunc (c *Client) Init(path string) error {\n\terr := c.runGo(context.Background(), c.logger.StdOut(), \"mod\", \"init\", path)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"failed to init modules: %w\", err)\n\t}\n\n\tc.GoModulesFilename = filepath.Join(c.ccfg.WorkingDir, goModFilename)\n\n\treturn nil\n}\n\nvar verifyErrorDirRe = regexp.MustCompile(`dir has been modified \\((.*?)\\)`)\n\n// Verify checks that the dependencies of the current module,\n// which are stored in a local downloaded source cache, have not been\n// modified since being downloaded.\nfunc (c *Client) Verify(clean bool) error {\n\t// TODO(bep) add path to mod clean\n\terr := c.runVerify()\n\tif err != nil {\n\t\tif clean {\n\t\t\tm := verifyErrorDirRe.FindAllStringSubmatch(err.Error(), -1)","sourceCodeStart":351,"sourceCodeEnd":387,"githubUrl":"https://github.com/gohugoio/hugo/blob/52c9bd7908b4d02d4d0ff8f82a888834d6ee10d2/modules/client.go#L351-L387","documentation":"Returned by Client.Init when c.runGo(... \"mod\" \"init\" <path>) fails, i.e. `go mod init <path>` exited non-zero. Wrapped with %w. On success the client sets GoModulesFilename so the project is treated as a Go module. The error usually means Go is not installed (though runGo records not-found silently, a real failure here is typically an invalid module path or an existing go.mod).","triggerScenarios":"Running `hugo mod init <path>` with a module path that violates Go module path rules (module.CheckPath), or when a go.mod already exists and Go refuses to re-init, or when Go is too old/absent in a way runGo does not silently swallow.","commonSituations":"Using a module path without a domain prefix (e.g. 'mysite' instead of 'github.com/user/mysite'); a go.mod already present in WorkingDir; corporate machine with a Go version older than Hugo requires; CI image missing the go toolchain.","solutions":["Provide a valid Go module path: a domain-prefixed path like 'github.com/user/project'.","Remove or back up an existing go.mod before running `hugo mod init` if you intend a fresh init.","Ensure the go toolchain is installed and recent: `go version`.","Reproduce with `go mod init <path>` directly to see Go's own error."],"exampleFix":"# before\nhugo mod init mysite   # invalid: not a valid module path\n\n# after\nhugo mod init github.com/user/mysite","handlingStrategy":"validation","validationCode":"// Validate the module path before running hugo mod init.\nfunc validModulePath(path string) error {\n    return module.CheckPath(path)\n}","typeGuard":"func isValidModulePath(path string) bool {\n    return module.CheckPath(path) == nil\n}","tryCatchPattern":"if err := client.Init(path); err != nil {\n    // likely invalid path or existing go.mod; surface go's message and retry\n}","preventionTips":["Use a domain-prefixed module path (e.g. github.com/user/repo).","Ensure no go.mod already exists, or remove it intentionally before init.","Install a recent Go toolchain so `go mod init` supports current behavior."],"tags":["modules","go-mod-init","go-modules","validation","initialization"],"backgroundTag":null,"analyzedSha":"52c9bd7908b4d02d4d0ff8f82a888834d6ee10d2","analyzedAt":"2026-08-09T21:49:36.660Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}