{"record":{"id":"3b684c18210e5dcd","repo":"golang/go","slug":"incorrect-number-of-packages-want-1-got-d","errorCode":null,"errorMessage":"incorrect number of packages: want 1, got %d","messagePattern":"incorrect number of packages: want 1, got (.+?)","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/cmd/go/internal/doc/mod.go","lineNumber":28,"sourceCode":"\t\"fmt\"\n\t\"os/exec\"\n\n\t\"cmd/go/internal/load\"\n\t\"cmd/go/internal/modload\"\n)\n\n// loadVersioned loads a package at a specific version.\nfunc loadVersioned(ctx context.Context, loader *modload.Loader, pkgPath, version string) (*load.Package, error) {\n\tvar opts load.PackageOpts\n\targs := []string{\n\t\tfmt.Sprintf(\"%s@%s\", pkgPath, version),\n\t}\n\tpkgs, err := load.PackagesAndErrorsOutsideModule(loader, ctx, opts, args)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\tif len(pkgs) != 1 {\n\t\treturn nil, fmt.Errorf(\"incorrect number of packages: want 1, got %d\", len(pkgs))\n\t}\n\treturn pkgs[0], nil\n}\n\n// inferVersion checks if the argument matches a command on $PATH and returns its module path and version.\nfunc inferVersion(arg string) (pkgPath, version string, ok bool) {\n\tpath, err := exec.LookPath(arg)\n\tif err != nil {\n\t\treturn \"\", \"\", false\n\t}\n\tbi, err := buildinfo.ReadFile(path)\n\tif err != nil {\n\t\treturn \"\", \"\", false\n\t}\n\tif bi.Main.Path == \"\" || bi.Main.Version == \"\" {\n\t\treturn \"\", \"\", false\n\t}\n\t// bi.Path is the package path for the main package.","sourceCodeStart":10,"sourceCodeEnd":46,"githubUrl":"https://github.com/golang/go/blob/b6b368adc57c96c3151d224d172029f233ead2c3/src/cmd/go/internal/doc/mod.go#L10-L46","documentation":"Returned by loadVersioned when PackagesAndErrorsOutsideModule for a single `pkgPath@version` argument does not yield exactly one package. The versioned-doc lookup assumes one package per (path, version); zero means the version/path is absent, two-plus means the spec resolved ambiguously.","triggerScenarios":"Running `go doc <pkg>@<version>` where the version does not exist, the module path is wrong, or the spec resolves to multiple packages (e.g. a meta-package or build-tag split).","commonSituations":"Typo in version tag (@v1.2 instead of @v1.2.0); pointing at a module path rather than a package path; version replaced/retired; ambiguous main/meta packages.","solutions":["Verify the version exists: `go list -m -versions <module>`.","Make sure you pass a package path, not just the module root path.","Use a fully-qualified semantic version (e.g. @v1.2.0, not @v1.2).","Check for replace directives that alter resolution."],"exampleFix":"# before\n$ go doc example.com/lib@v1.2\n# -> incorrect number of packages: want 1, got 0\n\n# after\n$ go list -m -versions example.com/lib   # find a real tag\n$ go doc example.com/lib@v1.2.0","handlingStrategy":"validation","validationCode":"// verify the version exists before the versioned doc call\nif out, err := exec.Command(\"go\", \"list\", \"-m\", \"-versions\", modPath).Output(); err != nil || !bytes.Contains(out, []byte(version)) {\n    return fmt.Errorf(\"version %s not available for %s\", version, modPath)\n}","typeGuard":"func looksLikeVersionedSpec(s string) bool {\n    return goVersionRegexp.MatchString(s) // e.g. pkg@v1.2.3\n}","tryCatchPattern":null,"preventionTips":["Always use fully-qualified semantic versions (v1.2.0, not v1.2).","Pass a package path, not just a module root.","Check `go list -m -versions` for available tags."],"tags":["doc","module","version","goproxy"],"backgroundTag":null,"analyzedSha":"b6b368adc57c96c3151d224d172029f233ead2c3","analyzedAt":"2026-08-12T00:22:02.250Z","schemaVersion":2},"datasetVersion":"2026-08-12T13:17:24.610Z"}