golangci/golangci-lint · error
failed to gob encode: %w
Error message
failed to gob encode: %w
What it means
Wrapping error in Cache.encode, called from Put: gob.NewEncoder(buf).Encode(data) failed while serializing cache data (typically an unencodable value type, unsupported field, or I/O error writing to the buffer). The raw gob error is wrapped with %w so the underlying cause is preserved; the cache write aborts.
Source
Thrown at internal/cache/cache.go:276
h, err := cache.FileHash(f)
<-c.ioSem
if err != nil {
return [cache.HashSize]byte{}, err
}
return h, nil
}
func (c *Cache) encode(data any) (*bytes.Buffer, error) {
buf := &bytes.Buffer{}
err := c.sw.TrackStageErr("gob", func() error {
return gob.NewEncoder(buf).Encode(data)
})
if err != nil {
return nil, fmt.Errorf("failed to gob encode: %w", err)
}
return buf, nil
}
func (c *Cache) decode(b []byte, data any) error {
err := c.sw.TrackStageErr("gob", func() error {
return gob.NewDecoder(bytes.NewReader(b)).Decode(data)
})
if err != nil {
return fmt.Errorf("failed to gob decode: %w", err)
}
return nil
}
func SetSalt(b *bytes.Buffer) {
cache.SetSalt(b.Bytes())View on GitHub (pinned to ed7a235d2d)
Solutions
- Inspect the wrapped gob error for the offending type or field
- Ensure cached values contain only gob-encodable types (no funcs, channels, or unexported-only fields)
- Clear a corrupted cache directory if the data format changed
Defensive patterns
Strategy: fallback
When it happens
Trigger: Thrown at internal/cache/cache.go:276 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of golangci/golangci-lint@ed7a235d2d (2026-09-02).
Data as JSON: /api/errors/569eeff4c92bab9e.
Report an issue: GitHub.