{"record":{"id":"a2e108f1d6e2b820","repo":"go-kratos/kratos","slug":"failed-to-get-relative-path-v","errorCode":null,"errorMessage":"🚫 failed to get relative path: %v","messagePattern":"🚫 failed to get relative path: (.+?)","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/kratos/internal/project/project.go","lineNumber":96,"sourceCode":"\t\tif err != nil {\n\t\t\tfmt.Fprintf(os.Stderr, \"\\033[31mERROR: failed to select repo(%s)\\033[m\\n\", err.Error())\n\t\t\treturn\n\t\t}\n\t}\n\tgo func() {\n\t\tif !nomod {\n\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","sourceCodeStart":78,"sourceCodeEnd":114,"githubUrl":"https://github.com/go-kratos/kratos/blob/668db92c2c001e9552594ba5a8aede8456af6d7e/cmd/kratos/internal/project/project.go#L78-L114","documentation":"While scaffolding in no-module mode, the CLI computes the new package path with filepath.Rel(projectRoot, workingDir/projectName). Go's Rel errors when one path cannot be made relative to the other (typically different drive letters on Windows, or roots sharing no common prefix), and the CLI wraps and reports it.","triggerScenarios":"filepath.Rel fails between the discovered go.mod root and workingDir/projectName — paths rooted on different Windows volumes, or symlink/junction-induced paths with no shared prefix.","commonSituations":"Repo checked out on one drive while the terminal cwd sits on another; subst/junction directories between cwd and the module root; unusual terminal starting directories.","solutions":["Ensure the working directory and the go.mod project root are on the same volume/drive (Windows: same drive letter)","Avoid subst/junction/symlink paths between cwd and the module root","Run the CLI from the repository root so the relative path is trivial"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"wd, _ := os.Getwd()\nroot := findProjectRoot(wd) // walks up to the nearest go.mod\nif _, err := filepath.Rel(root, filepath.Join(wd, newName)); err != nil {\n    log.Fatalf(\"cwd %s is not relative to %s (different volume?)\", wd, root)\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Keep the working directory and module root on the same drive/volume","Avoid subst/junction paths between cwd and the module","Run scaffolding commands from the repo root"],"tags":["cli","filesystem","windows","paths","go"],"backgroundTag":null,"analyzedSha":"668db92c2c001e9552594ba5a8aede8456af6d7e","analyzedAt":"2026-08-16T02:07:20.704Z","schemaVersion":2},"datasetVersion":"2026-08-16T03:17:38.424Z"}