{"record":{"id":"2e634cef536d9358","repo":"github/copilot-sdk","slug":"multiple-packages-q-and-q-found-in-q","errorCode":null,"errorMessage":"multiple packages %q and %q found in %q","messagePattern":"multiple packages %q and %q found in %q","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"go/cmd/bundler/main.go","lineNumber":251,"sourceCode":"\t\tif err != nil {\n\t\t\treturn defaultPackageName, fmt.Errorf(\"failed to evaluate build constraints in %q: %w\", filepath.Join(dir, name), err)\n\t\t}\n\t\tif !matches {\n\t\t\tcontinue\n\t\t}\n\n\t\tpath := filepath.Join(dir, name)\n\t\tfile, err := parser.ParseFile(token.NewFileSet(), path, nil, parser.PackageClauseOnly)\n\t\tif err != nil {\n\t\t\treturn defaultPackageName, fmt.Errorf(\"failed to parse package clause in %q: %w\", path, err)\n\t\t}\n\n\t\tif packageName == \"\" {\n\t\t\tpackageName = file.Name.Name\n\t\t\tcontinue\n\t\t}\n\t\tif packageName != file.Name.Name {\n\t\t\treturn defaultPackageName, fmt.Errorf(\"multiple packages %q and %q found in %q\", packageName, file.Name.Name, dir)\n\t\t}\n\t}\n\n\tif packageName == \"\" {\n\t\treturn defaultPackageName, fmt.Errorf(\"no Go package found in %q\", dir)\n\t}\n\treturn packageName, nil\n}\n\n// detectCLIVersion detects the CLI version by:\n// 1. Running \"go list -m\" to get the copilot-sdk version from the user's go.mod\n// 2. Fetching package.json from the SDK repo at that version\n// 3. Extracting the pinned Copilot CLI version from it\nfunc detectCLIVersion() (string, error) {\n\t// Get the SDK version from the user's go.mod\n\tsdkVersion, err := getSDKVersion()\n\tif err != nil {\n\t\treturn \"\", fmt.Errorf(\"failed to get SDK version: %w\", err)","sourceCodeStart":233,"sourceCodeEnd":269,"githubUrl":"https://github.com/github/copilot-sdk/blob/cd8cf15dc3f9e762615790aaed0a771a0f392755/go/cmd/bundler/main.go#L233-L269","documentation":"detectPackageName requires all .go files in a directory to belong to a single package (ignoring _test files per its logic). When a second, different package name is seen it abandons detection, falls back to defaultPackageName, and reports the two conflicting names. Mixed-package directories are not supported by the bundler.","triggerScenarios":"The bundled directory contains files from two different packages, e.g. both `package foo` and `package foo_test` or `package main` mixed with a library package, so the second file's name mismatches the first.","commonSituations":"Test helper files dropped into a library package directory; accidentally generated files with a different package header; hand-merging files from other packages into one folder.","solutions":["Move one of the conflicting packages' files into its own directory (Go convention: one package per directory)","Rename the test files' package to match the primary package (e.g. package foo for in-package tests)","If intentional, pass/exclude those files so the bundler only sees one package","Accept the fallback: the bundler proceeds with defaultPackageName, but prefer fixing the directory layout"],"exampleFix":"// before: pkg/util/client.go (package util) and pkg/util/helpers_test.go (package util_test)\n// after: move tests or unify\n// -package util_test\n// +package util","handlingStrategy":"validation","validationCode":"pkgs, err := parser.ParseDir(token.NewFileSet(), dir, nil, parser.PackageClauseOnly)\nif err == nil && len(pkgs) > 1 {\n    return fmt.Errorf(\"directory %s mixes packages: %v\", dir, keys(pkgs))\n}","typeGuard":null,"tryCatchPattern":"if err := bundle(dir); err != nil && strings.Contains(err.Error(), \"multiple packages\") {\n    // fall back to bundling a single-package subdirectory instead\n}","preventionTips":["Follow the one-package-per-directory convention","Name test files package foo (in-package tests) rather than foo_test when co-located","Keep generated files in their own package directories"],"tags":["go","bundling","packages","conflict"],"backgroundTag":"invalid-state-transition","analyzedSha":"cd8cf15dc3f9e762615790aaed0a771a0f392755","analyzedAt":"2026-09-09T18:32:31.973Z","contentChangedAt":"2026-09-09T18:32:31.973Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}