{"record":{"id":"1d14fbea368e35b6","repo":"golang/go","slug":"can-t-query-specific-version-q-of-standard-libr","errorCode":null,"errorMessage":"can't query specific version (%q) of standard-library module %q","messagePattern":"can't query specific version \\(%q\\) of standard-library module %q","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/cmd/go/internal/modload/query.go","lineNumber":223,"sourceCode":"\t\treturn nil, fmt.Errorf(\"invalid previous version %v@%v\", path, current)\n\t}\n\tif cfg.BuildMod == \"vendor\" {\n\t\treturn nil, errQueryDisabled\n\t}\n\tif allowed == nil {\n\t\tallowed = func(context.Context, module.Version) error { return nil }\n\t}\n\n\tif ld.MainModules.Contains(path) && (query == \"upgrade\" || query == \"patch\") {\n\t\tm := module.Version{Path: path}\n\t\tif err := allowed(ctx, m); err != nil {\n\t\t\treturn nil, fmt.Errorf(\"internal error: main module version is not allowed: %w\", err)\n\t\t}\n\t\treturn &modfetch.RevInfo{Version: m.Version}, nil\n\t}\n\n\tif path == \"std\" || path == \"cmd\" {\n\t\treturn nil, fmt.Errorf(\"can't query specific version (%q) of standard-library module %q\", query, path)\n\t}\n\n\trepo, err := lookupRepo(ld, ctx, proxy, path)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\n\tif old := reuse[module.Version{Path: path, Version: query}]; old != nil {\n\t\tif err := checkReuseRepo(ctx, repo, path, query, old.Origin); err == nil {\n\t\t\tinfo := &modfetch.RevInfo{\n\t\t\t\tVersion: old.Version,\n\t\t\t\tOrigin:  old.Origin,\n\t\t\t}\n\t\t\tif old.Time != nil {\n\t\t\t\tinfo.Time = *old.Time\n\t\t\t}\n\t\t\treturn info, nil\n\t\t}","sourceCodeStart":205,"sourceCodeEnd":241,"githubUrl":"https://github.com/golang/go/blob/b6b368adc57c96c3151d224d172029f233ead2c3/src/cmd/go/internal/modload/query.go#L205-L241","documentation":"Returned by queryProxy when the queried path is the standard-library module 'std' or 'cmd' and a specific version query is requested. The standard library is part of the toolchain and has no independent downloadable versions, so version queries against it are meaningless and rejected.","triggerScenarios":"Running 'go get std@v1.2.3', 'go list -m -versions std', 'go get cmd@latest', or any version-specific query targeting the std or cmd module path.","commonSituations":"Scripts or Makefiles that indiscriminately 'go get' every module in go.mod including std/cmd; copy-pasting a 'go get <path>@latest' loop that hits the standard library; tooling that resolves dependencies generically.","solutions":["Remove the version query for std/cmd — these are provided by the Go toolchain itself, not fetched.","If upgrading the standard library is the goal, upgrade the Go toolchain (e.g. via the 'toolchain' directive or installing a newer Go).","Filter std/cmd out of any batch 'go get' loop over required modules."],"exampleFix":"// before\n$ go get std@latest\n// error: can't query specific version (\"latest\") of standard-library module \"std\"\n\n// after\n$ go version   // std comes from this; upgrade Go to change it\n$ go get example.com/realdep@latest","handlingStrategy":"validation","validationCode":"// Skip version queries for standard-library modules:\n//   if path == \"std\" || path == \"cmd\" { /* do not call queryProxy with a version */ }","typeGuard":"func isQueryableModule(path string) bool {\n    return path != \"std\" && path != \"cmd\"\n}","tryCatchPattern":null,"preventionTips":["Filter std/cmd out of batch 'go get' loops.","Remember the standard library ships with the toolchain — upgrade Go, not modules.","Lint scripts that iterate over go.mod requires to skip std/cmd."],"tags":["go-modules","query","stdlib","validation"],"backgroundTag":null,"analyzedSha":"b6b368adc57c96c3151d224d172029f233ead2c3","analyzedAt":"2026-08-12T00:22:02.250Z","schemaVersion":2},"datasetVersion":"2026-08-12T13:17:24.610Z"}