golang/go · error
%s exists with wrong content (have %q want %q)
Error message
%s exists with wrong content (have %q want %q)
What it means
Thrown by codehost.WorkDir when the .info metadata file for a cached VCS checkout exists and the checkout directory exists, but the .info content (the key string 'type:name') does not match the computed key. This indicates the cache entry is stale, corrupted, or the hash function changed between go versions.
Source
Thrown at src/cmd/go/internal/modfetch/codehost/codehost.go:258
lockfile = dir + ".lock"
if buildX {
fmt.Fprintf(xLog, "# lock %s\n", lockfile)
}
unlock, err := lockedfile.MutexAt(lockfile).Lock()
if err != nil {
return "", "", fmt.Errorf("codehost.WorkDir: can't find or create lock file: %v", err)
}
defer unlock()
data, err := os.ReadFile(dir + ".info")
info, err2 := os.Stat(dir)
if err == nil && err2 == nil && info.IsDir() {
// Info file and directory both already exist: reuse.
have := strings.TrimSuffix(string(data), "\n")
if have != key {
return "", "", fmt.Errorf("%s exists with wrong content (have %q want %q)", dir+".info", have, key)
}
if buildX {
fmt.Fprintf(xLog, "# %s for %s %s\n", dir, typ, name)
}
return dir, lockfile, nil
}
// Info file or directory missing. Start from scratch.
if xLog != nil {
fmt.Fprintf(xLog, "mkdir -p %s # %s %s\n", dir, typ, name)
}
os.RemoveAll(dir)
if err := os.MkdirAll(dir, 0777); err != nil {
return "", "", err
}
if err := os.WriteFile(dir+".info", []byte(key), 0666); err != nil {
os.RemoveAll(dir)
return "", "", errView on GitHub (pinned to b6b368adc5)
Solutions
- Clear the VCS cache: 'go clean -cache' or 'rm -rf $(go env GOMODCACHE)/cache/vcs'.
- Retry the go command — it will re-clone fresh.
- If recurring, check filesystem health (fsck/disk diagnostics).
- Ensure only one go version writes to a given GOMODCACHE.
Example fix
# before: stale .info from old go version $ go get example.com/mod ... exists with wrong content ... # after go clean -cache go get example.com/mod
Defensive patterns
Strategy: fallback
Validate before calling
null
Type guard
null
Try / catch
null
Prevention
- Use one go version per GOMODCACHE to avoid key-derivation mismatches.
- Run 'go clean -cache' after major go version upgrades.
- Don't manually edit files under GOMODCACHE/cache/vcs.
- Don't copy cache directories between machines; let go rebuild them.
When it happens
Trigger: Accessing a cached VCS repo after upgrading go (the key derivation or directory layout changed), after manual tampering with the cache, or after a filesystem corruption event.
Common situations: Downgrading or upgrading across major go versions that changed the cache layout; running 'go clean -cache' partially; disk corruption; copying a cache between machines with different architectures where the hash input differs.
Related errors
AI-assisted analysis of golang/go@b6b368adc5 (2026-08-12).
Data as JSON: /api/errors/a33907c8e59eda4a.
Report an issue: GitHub.