{"record":{"id":"c57f35ff2dfa5ccf","repo":"go-delve/delve","slug":"could-not-determine-path-for-module-s-got-q-and","errorCode":null,"errorMessage":"could not determine path for module %s (got %q and %q)","messagePattern":"could not determine path for module (.+?) \\(got %q and %q\\)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"service/rpc2/client.go","lineNumber":669,"sourceCode":"\t\tif e.Module == nil {\n\t\t\tcontinue\n\t\t}\n\t\tif !strings.HasPrefix(e.ImportPath, e.Module.Path) {\n\t\t\tcontinue\n\t\t}\n\t\tpkgWithoutModule := e.ImportPath[len(e.Module.Path):]\n\t\telems := 0\n\t\tfor _, c := range pkgWithoutModule {\n\t\t\tif c == '/' {\n\t\t\t\telems++\n\t\t\t}\n\t\t}\n\t\tdir := e.Dir\n\t\tfor i := 0; i < elems; i++ {\n\t\t\tdir = filepath.Dir(dir)\n\t\t}\n\t\tif mod2dir[e.Module.Path] != \"\" && mod2dir[e.Module.Path] != dir {\n\t\t\treturn nil, fmt.Errorf(\"could not determine path for module %s (got %q and %q)\", e.Module.Path, mod2dir[e.Module.Path], dir)\n\t\t}\n\t\tmod2dir[e.Module.Path] = dir\n\t\tif e.Name == \"main\" {\n\t\t\tif importPathOfMainPackage != \"\" && importPathOfMainPackage != e.ImportPath {\n\t\t\t\timportPathOfMainPackageOk = false\n\t\t\t}\n\t\t\timportPathOfMainPackage = e.ImportPath\n\t\t}\n\t}\n\tbuf, err = exec.Command(\"go\", \"env\", \"GOROOT\").Output()\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\tclientGoroot := strings.TrimSpace(string(buf))\n\tif !importPathOfMainPackageOk {\n\t\t// There were multiple main packages\n\t\timportPathOfMainPackage = \"\"\n\t}","sourceCodeStart":651,"sourceCodeEnd":687,"githubUrl":"https://github.com/go-delve/delve/blob/a23773e6c31361e43246bc43a424ee009679b174/service/rpc2/client.go#L651-L687","documentation":"While building the module substitute-path map, 'go list' output assigned two different directories to the same module path after trimming the expected number of path elements, so the mapping is ambiguous and MakeGuessSusbtitutePathIn aborts with this error. Indicates module metadata that does not match the on-disk layout.","triggerScenarios":"GuessSubstitutePathIn RPC where a module appears multiple times in 'go list --json all' output with conflicting computed Dir values (after filepath.Dir applied elems times).","commonSituations":"Vendor directories mixed with module cache copies; replace directives pointing at local forks; monorepo layouts where module depth (elems) doesn't match directory structure; stale module cache.","solutions":["Clean the module cache: go clean -modcache, then rebuild","Remove or fix conflicting replace directives in go.mod","Ensure the program is built with the same module layout you debug against","Fall back to configuring substitutePath manually in your client instead of guessing"],"exampleFix":"// before\nsub, err := client.MakeGuessSusbtitutePathIn() // ambiguous module path\n// after\n// fix go.mod replace directives, then:\nsub, err := client.MakeGuessSusbtitutePathIn()\n// or set client.SubstitutePath manually","handlingStrategy":"fallback","validationCode":"// inspect module list for duplicates before trusting the mapping\ncmd := exec.Command(\"go\", \"list\", \"-m\", \"all\")\nout, err := cmd.Output()\nhasDup := func(mod string) bool { return strings.Count(string(out), mod) > 1 }","typeGuard":null,"tryCatchPattern":"sub, err := client.MakeGuessSusbtitutePathIn()\nif err != nil && strings.Contains(err.Error(), \"could not determine path for module\") {\n    // use explicit client.SubstitutePath entries instead of guessed ones\n}","preventionTips":["Avoid conflicting replace directives pointing at multiple copies of one module","Run go clean -modcache when module layout seems stale","Keep vendor/ and module cache usage consistent","Pin substitutePath in your IDE config instead of relying on guessing"],"tags":["go-modules","rpc2","substitute-path"],"backgroundTag":"module-path-ambiguous","analyzedSha":"a23773e6c31361e43246bc43a424ee009679b174","analyzedAt":"2026-08-31T15:12:45.221Z","schemaVersion":2},"datasetVersion":"2026-08-31T19:17:28.585Z"}