{"record":{"id":"c27c5adc3249d209","repo":"golang/go","slug":"path-q-matched-multiple-packages","errorCode":null,"errorMessage":"path %q matched multiple packages","messagePattern":"path %q matched multiple packages","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"src/cmd/go/internal/doc/doc.go","lineNumber":632,"sourceCode":"\t// not fall through to internal-only matches for the same package path.\n\tnonInternal[len(nonInternal)-1].nextOffset = dirs.offset\n\treturn append(nonInternal, internal...)\n}\n\nfunc loadPackage(ctx context.Context, loader *modload.Loader, pattern string) (*load.Package, error) {\n\tif !search.NewMatch(pattern).IsLiteral() {\n\t\treturn nil, fmt.Errorf(\"pattern %q does not specify a single package\", pattern)\n\t}\n\n\tpkgOpts := load.PackageOpts{\n\t\tIgnoreImports:      true,\n\t\tSuppressBuildInfo:  true,\n\t\tSuppressEmbedFiles: true,\n\t}\n\tpkgs := load.PackagesAndErrors(loader, ctx, pkgOpts, []string{pattern})\n\n\tif len(pkgs) != 1 {\n\t\treturn nil, fmt.Errorf(\"path %q matched multiple packages\", pattern)\n\t}\n\n\tp := pkgs[0]\n\tif p.Error != nil {\n\t\treturn nil, p.Error\n\t}\n\treturn p, nil\n}\n\nfunc mustLoadPackage(ctx context.Context, loader *modload.Loader, dir string) *load.Package {\n\tpkg, err := loadPackage(ctx, loader, dir)\n\tif err != nil {\n\t\tlog.Fatal(err)\n\t}\n\treturn pkg\n}\n\n// dotPaths lists all the dotted paths legal on Unix-like and","sourceCodeStart":614,"sourceCodeEnd":650,"githubUrl":"https://github.com/golang/go/blob/b6b368adc57c96c3151d224d172029f233ead2c3/src/cmd/go/internal/doc/doc.go#L614-L650","documentation":"Returned by loadPackage after PackagesAndErrors returned a count other than 1 for a literal pattern. A literal path resolving to multiple packages is ambiguous — typically because build constraints or _test suffix produce more than one loadable package for the same directory.","triggerScenarios":"A directory that yields multiple packages under the active build tags (e.g. a package and its _test variant, or files split by build tags into two importable packages); passing a path that aliases two modules.","commonSituations":"Build-tag-separated packages in one dir; both foo and foo_test present; vendor + module path collision; ambiguous import after a module rename.","solutions":["Disambiguate with build tags or by selecting the specific package variant.","Run `go list <pattern>` to see all matches and pick one.","Reorganize the directory so one path == one package.","Remove the _test ambiguity by aligning package names."],"exampleFix":"# before\n$ go doc ./splitpkg\n# -> path \"./splitpkg\" matched multiple packages\n\n# after: see the matches, then target one\n$ go list ./splitpkg\n$ go doc ./splitpkg  # after resolving the build-tag split","handlingStrategy":"validation","validationCode":"out, err := exec.Command(\"go\", \"list\", pattern).Output()\nif err == nil && len(bytes.Split(out, []byte(\"\\n\"))) > 1 {\n    return fmt.Errorf(\"%q matches multiple packages; narrow it down\", pattern)\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Run `go list <path>` to count matches before `go doc`.","Keep one importable package per directory.","Align package names to avoid _test ambiguity."],"tags":["doc","package","ambiguous","build-tags"],"analyzedSha":"b6b368adc57c96c3151d224d172029f233ead2c3","analyzedAt":"2026-08-12T00:22:02.250Z","schemaVersion":2},"datasetVersion":"2026-08-12T08:17:17.861Z"}