golang/go · error
invalid previous version %v@%v
Error message
invalid previous version %v@%v
What it means
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).
Source
Thrown at src/cmd/go/internal/modload/query.go:205
type AllowedFunc func(context.Context, module.Version) error
var errQueryDisabled error = queryDisabledError{}
type queryDisabledError struct{}
func (queryDisabledError) Error() string {
if cfg.BuildModReason == "" {
return fmt.Sprintf("cannot query module due to -mod=%s", cfg.BuildMod)
}
return fmt.Sprintf("cannot query module due to -mod=%s\n\t(%s)", cfg.BuildMod, cfg.BuildModReason)
}
func queryProxy(ld *Loader, ctx context.Context, proxy, path, query, current string, allowed AllowedFunc, reuse map[module.Version]*modinfo.ModulePublic) (*modfetch.RevInfo, error) {
ctx, span := trace.StartSpan(ctx, "modload.queryProxy "+path+" "+query)
defer span.Done()
if current != "" && current != "none" && !gover.ModIsValid(path, current) {
return nil, fmt.Errorf("invalid previous version %v@%v", path, current)
}
if cfg.BuildMod == "vendor" {
return nil, errQueryDisabled
}
if allowed == nil {
allowed = func(context.Context, module.Version) error { return nil }
}
if ld.MainModules.Contains(path) && (query == "upgrade" || query == "patch") {
m := module.Version{Path: path}
if err := allowed(ctx, m); err != nil {
return nil, fmt.Errorf("internal error: main module version is not allowed: %w", err)
}
return &modfetch.RevInfo{Version: m.Version}, nil
}
if path == "std" || path == "cmd" {
return nil, fmt.Errorf("can't query specific version (%q) of standard-library module %q", query, path)View on GitHub (pinned to b6b368adc5)
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.
Example fix
// before // error: invalid previous version example.com/pkg@main // after $ go get example.com/pkg@v1.2.3
Defensive patterns
Strategy: validation
Validate before calling
// Validate a current version is well-formed before passing to queryProxy:
// if current != "" && current != "none" && !gover.ModIsValid(path, current) {
// return fmt.Errorf("refusing to query: bad current version %q", current)
// } Type guard
func isValidCurrentVersion(path, current string) bool {
return current == "" || current == "none" || gover.ModIsValid(path, current)
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- invalid semantic version %q in range %q
- can't query specific version (%q) of standard-library module
- ambiguous semantic version %q in range %q
- revision is longer than canonical (expected %s)
- revision is shorter than canonical (expected %s)
AI-assisted analysis of golang/go@b6b368adc5 (2026-08-12).
Data as JSON: /api/errors/6b6a094f18f71bfb.
Report an issue: GitHub.