{"record":{"id":"6b6a094f18f71bfb","repo":"golang/go","slug":"invalid-previous-version-v-v","errorCode":null,"errorMessage":"invalid previous version %v@%v","messagePattern":"invalid previous version (.+?)@(.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/cmd/go/internal/modload/query.go","lineNumber":205,"sourceCode":"type AllowedFunc func(context.Context, module.Version) error\n\nvar errQueryDisabled error = queryDisabledError{}\n\ntype queryDisabledError struct{}\n\nfunc (queryDisabledError) Error() string {\n\tif cfg.BuildModReason == \"\" {\n\t\treturn fmt.Sprintf(\"cannot query module due to -mod=%s\", cfg.BuildMod)\n\t}\n\treturn fmt.Sprintf(\"cannot query module due to -mod=%s\\n\\t(%s)\", cfg.BuildMod, cfg.BuildModReason)\n}\n\nfunc queryProxy(ld *Loader, ctx context.Context, proxy, path, query, current string, allowed AllowedFunc, reuse map[module.Version]*modinfo.ModulePublic) (*modfetch.RevInfo, error) {\n\tctx, span := trace.StartSpan(ctx, \"modload.queryProxy \"+path+\" \"+query)\n\tdefer span.Done()\n\n\tif current != \"\" && current != \"none\" && !gover.ModIsValid(path, current) {\n\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)","sourceCodeStart":187,"sourceCodeEnd":223,"githubUrl":"https://github.com/golang/go/blob/b6b368adc57c96c3151d224d172029f233ead2c3/src/cmd/go/internal/modload/query.go#L187-L223","documentation":"Returned by queryProxy at the start of a proxy query when a 'current' version string was supplied that is non-empty, not the literal 'none', and fails gover.ModIsValid. It guards the rest of the query logic against operating on a non-semver current version (e.g. a bare revision hash or malformed string).","triggerScenarios":"A go command invokes queryProxy with a current version that is not valid semantic version syntax — e.g. a commit SHA, a branch name, or a malformed string recorded as the module's current version.","commonSituations":"A go.mod or module cache entry holds a non-semver current version; a custom caller of the internal query API passes an unchecked string; a VCS pseudo-version got corrupted.","solutions":["Ensure the module's current version in go.mod / cache is a valid canonical semver (vMAJOR.MINOR.PATCH[-pre][+build]).","Run 'go get <module>@<valid-semver>' to replace the bad current version with a clean one.","Clear the offending cache entry with 'go clean -modcache' and re-resolve."],"exampleFix":"// before\n// error: invalid previous version example.com/pkg@main\n\n// after\n$ go get example.com/pkg@v1.2.3","handlingStrategy":"validation","validationCode":"// Validate a current version is well-formed before passing to queryProxy:\n//   if current != \"\" && current != \"none\" && !gover.ModIsValid(path, current) {\n//       return fmt.Errorf(\"refusing to query: bad current version %q\", current)\n//   }","typeGuard":"func isValidCurrentVersion(path, current string) bool {\n    return current == \"\" || current == \"none\" || gover.ModIsValid(path, current)\n}","tryCatchPattern":null,"preventionTips":["Never store non-semver strings (branches, SHAs) as a module's current version in go.mod.","When scripting queries, canonicalize the current version with module.CanonicalVersion first.","Run 'go mod tidy' to normalize versions in go.mod into canonical semver."],"tags":["go-modules","query","semver","validation"],"analyzedSha":"b6b368adc57c96c3151d224d172029f233ead2c3","analyzedAt":"2026-08-12T00:22:02.250Z","schemaVersion":2},"datasetVersion":"2026-08-12T06:17:24.410Z"}