go-kratos/kratos Β· error
π« failed to get relative path: %v
Error message
π« failed to get relative path: %v
What it means
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.
Source
Thrown at cmd/kratos/internal/project/project.go:96
if err != nil {
fmt.Fprintf(os.Stderr, "\033[31mERROR: failed to select repo(%s)\033[m\n", err.Error())
return
}
}
go func() {
if !nomod {
done <- p.New(ctx, workingDir, repoURL, branch)
return
}
projectRoot := getgomodProjectRoot(workingDir)
if gomodIsNotExistIn(projectRoot) {
done <- fmt.Errorf("π« go.mod don't exists in %s", projectRoot)
return
}
packagePath, e := filepath.Rel(projectRoot, filepath.Join(workingDir, projectName))
if e != nil {
done <- fmt.Errorf("π« failed to get relative path: %v", e)
return
}
packagePath = strings.ReplaceAll(packagePath, "\\", "/")
mod, e := base.ModulePath(filepath.Join(projectRoot, "go.mod"))
if e != nil {
done <- fmt.Errorf("π« failed to parse `go.mod`: %v", e)
return
}
// Get the relative path for adding a project based on Go modules
p.Path = filepath.Join(strings.TrimPrefix(workingDir, projectRoot+"/"), p.Name)
done <- p.Add(ctx, workingDir, repoURL, branch, mod, packagePath)
}()
select {
case <-ctx.Done():
if errors.Is(ctx.Err(), context.DeadlineExceeded) {
fmt.Fprint(os.Stderr, "\033[31mERROR: project creation timed out\033[m\n")
returnView on GitHub (pinned to 668db92c2c)
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
Defensive patterns
Strategy: validation
Validate before calling
wd, _ := os.Getwd()
root := findProjectRoot(wd) // walks up to the nearest go.mod
if _, err := filepath.Rel(root, filepath.Join(wd, newName)); err != nil {
log.Fatalf("cwd %s is not relative to %s (different volume?)", wd, root)
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- π« go.mod don't exists in %s
- π« failed to parse `go.mod`: %v
- %s already exists
- unable to parse repo url
- RATELIMIT
AI-assisted analysis of go-kratos/kratos@668db92c2c (2026-08-16).
Data as JSON: /api/errors/a2e108f1d6e2b820.
Report an issue: GitHub.