{"record":{"id":"4d20f504fb3291ac","repo":"go-kratos/kratos","slug":"failed-to-parse-go-mod-v","errorCode":null,"errorMessage":"🚫 failed to parse `go.mod`: %v","messagePattern":"🚫 failed to parse `go\\.mod`: (.+?)","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/kratos/internal/project/project.go","lineNumber":103,"sourceCode":"\t\t\tdone <- p.New(ctx, workingDir, repoURL, branch)\n\t\t\treturn\n\t\t}\n\t\tprojectRoot := getgomodProjectRoot(workingDir)\n\t\tif gomodIsNotExistIn(projectRoot) {\n\t\t\tdone <- fmt.Errorf(\"🚫 go.mod don't exists in %s\", projectRoot)\n\t\t\treturn\n\t\t}\n\n\t\tpackagePath, e := filepath.Rel(projectRoot, filepath.Join(workingDir, projectName))\n\t\tif e != nil {\n\t\t\tdone <- fmt.Errorf(\"🚫 failed to get relative path: %v\", e)\n\t\t\treturn\n\t\t}\n\t\tpackagePath = strings.ReplaceAll(packagePath, \"\\\\\", \"/\")\n\n\t\tmod, e := base.ModulePath(filepath.Join(projectRoot, \"go.mod\"))\n\t\tif e != nil {\n\t\t\tdone <- fmt.Errorf(\"🚫 failed to parse `go.mod`: %v\", e)\n\t\t\treturn\n\t\t}\n\t\t// Get the relative path for adding a project based on Go modules\n\t\tp.Path = filepath.Join(strings.TrimPrefix(workingDir, projectRoot+\"/\"), p.Name)\n\t\tdone <- p.Add(ctx, workingDir, repoURL, branch, mod, packagePath)\n\t}()\n\tselect {\n\tcase <-ctx.Done():\n\t\tif errors.Is(ctx.Err(), context.DeadlineExceeded) {\n\t\t\tfmt.Fprint(os.Stderr, \"\\033[31mERROR: project creation timed out\\033[m\\n\")\n\t\t\treturn\n\t\t}\n\t\tfmt.Fprintf(os.Stderr, \"\\033[31mERROR: failed to create project(%s)\\033[m\\n\", ctx.Err().Error())\n\tcase err = <-done:\n\t\tif err != nil {\n\t\t\tfmt.Fprintf(os.Stderr, \"\\033[31mERROR: Failed to create project(%s)\\033[m\\n\", err.Error())\n\t\t}\n\t}","sourceCodeStart":85,"sourceCodeEnd":121,"githubUrl":"https://github.com/go-kratos/kratos/blob/668db92c2c001e9552594ba5a8aede8456af6d7e/cmd/kratos/internal/project/project.go#L85-L121","documentation":"After locating the module root in no-module mode, the CLI reads go.mod via base.ModulePath to extract the module path. If the file cannot be read or the module directive cannot be extracted (empty, truncated, or malformed go.mod), the parse error is wrapped and creation aborts.","triggerScenarios":"base.ModulePath(projectRoot/go.mod) returns an error — file unreadable, empty, or missing a valid module directive.","commonSituations":"Hand-edited go.mod with syntax errors; aborted tooling leaving an empty go.mod; merge-conflict markers left in go.mod; permissions problems.","solutions":["Run go mod tidy / go mod init <path> in the project root and confirm go build succeeds","Open go.mod and make sure the first non-comment line is a valid module <path> directive","Check go.mod permissions and content integrity (no truncation or conflict markers)"],"exampleFix":"# before - go.mod with no module directive\ngo 1.22\n\n# after\nmodule github.com/me/shop\ngo 1.22","handlingStrategy":"validation","validationCode":"out, err := exec.Command(\"go\", \"mod\", \"edit\", \"-json\").Output()\nif err != nil {\n    log.Fatal(err)\n}\nvar m struct {\n    Module struct{ Path string }\n}\n_ = json.Unmarshal(out, &m)\nif m.Module.Path == \"\" {\n    log.Fatal(\"go.mod has no module directive\")\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Validate go.mod with `go mod edit -json` after manual edits","Never leave an empty go.mod behind from aborted tooling","Run go build once before scaffolding"],"tags":["cli","go-modules","parsing","go"],"backgroundTag":null,"analyzedSha":"668db92c2c001e9552594ba5a8aede8456af6d7e","analyzedAt":"2026-08-16T02:07:20.704Z","schemaVersion":2},"datasetVersion":"2026-08-16T03:17:38.424Z"}