golang/go · error · entryNotFoundError
file is empty
Error message
file is empty
What it means
The entry file exists on disk but io.ReadFull returns io.EOF immediately, meaning zero bytes were read. This indicates the file was created but never properly written — typically from a crash or power loss during a cache write operation. The entry is a zero-byte stub where valid content should be.
Source
Thrown at src/cmd/go/internal/cache/cache.go:215
Time time.Time // when added to cache
}
// get is Get but does not respect verify mode, so that Put can use it.
func (c *DiskCache) get(id ActionID) (Entry, error) {
missing := func(reason error) (Entry, error) {
return Entry{}, &entryNotFoundError{Err: reason}
}
f, err := os.Open(c.fileName(id, "a"))
if err != nil {
return missing(err)
}
defer f.Close()
entry := make([]byte, entrySize+1) // +1 to detect whether f is too long
if n, err := io.ReadFull(f, entry); n > entrySize {
return missing(errors.New("too long"))
} else if err != io.ErrUnexpectedEOF {
if err == io.EOF {
return missing(errors.New("file is empty"))
}
return missing(err)
} else if n < entrySize {
return missing(errors.New("entry file incomplete"))
}
if entry[0] != 'v' || entry[1] != '1' || entry[2] != ' ' || entry[3+hexSize] != ' ' || entry[3+hexSize+1+hexSize] != ' ' || entry[3+hexSize+1+hexSize+1+20] != ' ' || entry[entrySize-1] != '\n' {
return missing(errors.New("invalid header"))
}
eid, entry := entry[3:3+hexSize], entry[3+hexSize:]
eout, entry := entry[1:1+hexSize], entry[1+hexSize:]
esize, entry := entry[1:1+20], entry[1+20:]
etime, entry := entry[1:1+20], entry[1+20:]
var buf [HashSize]byte
if _, err := hex.Decode(buf[:], eid); err != nil {
return missing(fmt.Errorf("decoding ID: %v", err))
} else if buf != id {
return missing(errors.New("mismatched ID"))
}View on GitHub (pinned to b6b368adc5)
Solutions
- Run go clean -cache to remove corrupt zero-byte entries
- Check available disk space on the GOCACHE volume (df -h)
- Run filesystem integrity checks (fsck, SMART diagnostics)
- Ensure no other process is writing to the same cache directory simultaneously
Example fix
// before: stale zero-byte cache entries from a crash // $ go build ./... # fails with 'cache entry not found: file is empty' // after: clean cache and rebuild // $ go clean -cache && go build ./... // optionally check disk space first // $ df -h $(go env GOCACHE)
Defensive patterns
Strategy: try-catch
Validate before calling
// Check that the cache directory has sufficient free space
// and that the disk is writable before builds.
import "syscall"
func checkCacheDiskSpace(cacheDir string, minBytes uint64) error {
var stat syscall.Statfs_t
if err := syscall.Statfs(cacheDir, &stat); err != nil {
return err
}
free := stat.Bavail * uint64(stat.Bsize)
if free < minBytes {
return fmt.Errorf("cache dir %s has only %d bytes free (need %d)", cacheDir, free, minBytes)
}
return nil
} Type guard
// Same as error 80 — all cache get errors are wrapped in *entryNotFoundError.
// Check by error message prefix since the type is unexported.
func isEmptyCacheEntry(err error) bool {
return err != nil && strings.Contains(err.Error(), "file is empty")
} Try / catch
// entry, err := cache.Get(id)
// if err != nil {
// // 'file is empty' means a zero-byte entry from a crashed write.
// // Treat as cache miss and rebuild.
// output = rebuild()
// }
// For automated recovery, periodically clean stale entries:
// $ go clean -cache // full clean
// or set up a cron to clean old cache files Prevention
- Ensure adequate disk space before large builds (cache + output space)
- Use UPS or reliable power to prevent crashes during writes
- Configure antivirus to exclude the GOCACHE directory from scanning
- Run go clean -cache periodically as preventive maintenance
When it happens
Trigger: DiskCache.get(id) opens the entry file via os.Open and io.ReadFull returns 0 bytes with err == io.EOF (the very first read hit end-of-file).
Common situations: System crash or power failure interrupted a cache write; filesystem ran out of space mid-write leaving an empty file; antivirus quarantined a partially written file; concurrent processes racing on the same cache directory causing partial writes.
Related errors
AI-assisted analysis of golang/go@b6b368adc5 (2026-08-12).
Data as JSON: /api/errors/8a280338a515f162.
Report an issue: GitHub.