{"record":{"id":"253975b27a7a24e8","repo":"github/copilot-sdk","slug":"failed-to-get-sdk-version-w","errorCode":null,"errorMessage":"failed to get SDK version: %w","messagePattern":"failed to get SDK version: %w","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"go/cmd/bundler/main.go","lineNumber":269,"sourceCode":"\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)\n\t}\n\n\tfmt.Printf(\"Found copilot-sdk %s in go.mod\\n\", sdkVersion)\n\n\t// Fetch package.json from the SDK repo at that version\n\tcliVersion, err := fetchCLIVersionFromRepo(sdkVersion)\n\tif err != nil {\n\t\treturn \"\", fmt.Errorf(\"failed to fetch CLI version: %w\", err)\n\t}\n\n\treturn cliVersion, nil\n}\n\n// getSDKVersion runs \"go list -m\" to get the copilot-sdk version from go.mod\nfunc getSDKVersion() (string, error) {\n\tcmd := exec.Command(\"go\", \"list\", \"-m\", \"-f\", \"{{.Version}}\", sdkModule)\n\toutput, err := cmd.Output()\n\tif err != nil {","sourceCodeStart":251,"sourceCodeEnd":287,"githubUrl":"https://github.com/github/copilot-sdk/blob/cd8cf15dc3f9e762615790aaed0a771a0f392755/go/cmd/bundler/main.go#L251-L287","documentation":"detectCLIVersion resolves the pinned Copilot CLI version by first reading the copilot-sdk module version from go.mod via getSDKVersion. If that sub-step fails, the error is wrapped as 'failed to get SDK version'. The SDK version is the prerequisite for fetching the CLI version from the SDK repo.","triggerScenarios":"Running the bundler in a project where `go list -m -f {{.Version}} github.com/.../copilot-sdk` fails: the module is absent from go.mod, the module cache/sum is inconsistent, or go cannot resolve the module.","commonSituations":"Forgetting to `go get` / `go mod tidy` the copilot-sdk dependency; working in a module outside the one that requires copilot-sdk; GOFLAGS/proxy issues breaking module resolution.","solutions":["Run `go mod tidy` to add/repair the copilot-sdk requirement in go.mod","Run `go get copilot-sdk@latest` (or the desired version) then retry the bundler","Inspect the wrapped cause (%w) for the underlying `go list` failure and fix it","Ensure you run the bundler from within the Go module that depends on copilot-sdk"],"exampleFix":"// before: bundler fails: failed to get SDK version ...\n// after:\n// $ go get github.com/github/copilot-sdk@latest\n// $ go mod tidy\n// $ bundler ./cmd/app","handlingStrategy":"retry","validationCode":"out, err := exec.Command(\"go\", \"list\", \"-m\", \"-f\", \"{{.Version}}\", \"github.com/github/copilot-sdk\").Output()\nif err != nil || len(bytes.TrimSpace(out)) == 0 {\n    return errors.New(\"copilot-sdk not resolvable; run go mod tidy\")\n}","typeGuard":null,"tryCatchPattern":"if _, err := resolveCLIVersion(); err != nil {\n    if strings.Contains(err.Error(), \"failed to get SDK version\") {\n        exec.Command(\"go\", \"mod\", \"tidy\").Run() // repair module state, then retry\n    }\n}","preventionTips":["Always `go get` copilot-sdk and `go mod tidy` before bundling","Run the bundler from inside the module directory that requires the SDK","Keep go.sum in sync in CI"],"tags":["go","modules","versioning","cli"],"backgroundTag":"missing-dependency","analyzedSha":"cd8cf15dc3f9e762615790aaed0a771a0f392755","analyzedAt":"2026-09-09T18:32:31.973Z","contentChangedAt":"2026-09-09T18:32:31.973Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}