{"record":{"id":"19795e81cbdbc271","repo":"vitessio/vitess","slug":"must-specify-exactly-one-package","errorCode":null,"errorMessage":"must specify exactly one package","messagePattern":"must specify exactly one package","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"go/vt/vtctl/vtctldclient/codegen/main.go","lineNumber":302,"sourceCode":"func addImport(localImport string, pkgPath string, importNames []string, imports map[string]string) []string {\n\tif _, ok := imports[localImport]; !ok {\n\t\timportNames = append(importNames, localImport)\n\t}\n\n\timports[localImport] = pkgPath\n\treturn importNames\n}\n\nfunc loadPackage(source string) (*packages.Package, error) {\n\tpkgs, err := packages.Load(&packages.Config{\n\t\tMode: packages.NeedTypes | packages.NeedSyntax | packages.NeedTypesInfo,\n\t}, source)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\n\tif len(pkgs) != 1 {\n\t\treturn nil, errors.New(\"must specify exactly one package\")\n\t}\n\n\tpkg := pkgs[0]\n\tif len(pkg.Errors) > 0 {\n\t\tvar err error\n\n\t\tfor _, e := range pkg.Errors {\n\t\t\tswitch err {\n\t\t\tcase nil:\n\t\t\t\terr = fmt.Errorf(\"errors loading package %s: %s\", source, e.Error())\n\t\t\tdefault:\n\t\t\t\terr = fmt.Errorf(\"%w; %s\", err, e.Error())\n\t\t\t}\n\t\t}\n\n\t\treturn nil, err\n\t}\n","sourceCodeStart":284,"sourceCodeEnd":320,"githubUrl":"https://github.com/vitessio/vitess/blob/01a25a7d176f94613b8d59d799f438380a8760e4/go/vt/vtctl/vtctldclient/codegen/main.go#L284-L320","documentation":"This error comes from the codegen helper in vtctldclient that loads a Go package pattern via golang.org/x/tools/go/packages. It enforces that exactly one package matches the given pattern; zero or multiple matching packages make code generation ambiguous, so loadPackage fails.","triggerScenarios":"Running the vtctldclient codegen (go run ./go/vt/vtctl/vtctldclient/codegen) with a package pattern that matches zero packages (wrong path/typo) or more than one package (a directory containing multiple packages, or a broad pattern like ./...).","commonSituations":"Regenerating the vtctldclient command stubs after moving/renaming proto service files; running codegen from the wrong working directory; a directory containing both package foo and foo_test packages.","solutions":["Run codegen from the repository root with the default/expected package pattern","Verify the package path passed to loadPackage exists and names exactly one package","Ensure the target directory contains a single package (no mixed package names, exclude _test packages from the pattern)"],"exampleFix":"// before\ngo run ./go/vt/vtctl/vtctldclient/codegen ./go/vt/proto/...\n// after\ngo run ./go/vt/vtctl/vtctldclient/codegen ./go/vt/proto/vtctlservicepb","handlingStrategy":"validation","validationCode":"cfg := &packages.Config{Mode: packages.NeedName | packages.NeedFiles}\npkgs, err := packages.Load(cfg, pattern)\nif err != nil { return err }\nif len(pkgs) != 1 {\n    return fmt.Errorf(\"pattern %q matched %d packages, need exactly 1\", pattern, len(pkgs))\n}","typeGuard":"func exactlyOnePackage(pkgs []*packages.Package) bool { return len(pkgs) == 1 }","tryCatchPattern":"if _, err := loadPackage(pattern); err != nil {\n    if strings.Contains(err.Error(), \"must specify exactly one package\") {\n        return fmt.Errorf(\"codegen input error: %w\", err)\n    }\n    return err\n}","preventionTips":["Run codegen from the repo root with the exact documented package path","Avoid wildcard patterns like ./... in codegen inputs","Check target directories contain a single package name"],"tags":["codegen","go-packages","build-tooling"],"backgroundTag":"package-resolution-failed","analyzedSha":"01a25a7d176f94613b8d59d799f438380a8760e4","analyzedAt":"2026-09-01T17:28:30.605Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}