JuliusBrussee/caveman · error
zstd reader
Error message
zstd reader: %w
What it means
DecompressLimit wraps zstd.NewReader construction failures with 'zstd reader:'. The library throws it when the zstd decoder cannot be created — practically only when the configured decoder memory limit (maxBytes-derived) is invalid. Unlike gzip, reader setup itself can fail here.
Solutions
- Pass a positive, sane maxBytes (>=1) to DecompressLimit so the decoder memory limit is valid.
- Validate the limit from config before calling (reject 0/negative at config load).
- If the error persists on valid input, check the klauspost/compress zstd dependency version for regressions.
Example fix
// before
out, err := objectstore.DecompressLimit(data, objectstore.CompressionZstd, cfg.MaxBytes) // cfg.MaxBytes == 0
// after
if cfg.MaxBytes <= 0 {
return fmt.Errorf("decompression limit must be positive, got %d", cfg.MaxBytes)
}
out, err := objectstore.DecompressLimit(data, objectstore.CompressionZstd, cfg.MaxBytes) Defensive patterns
Strategy: validation
Validate before calling
if maxBytes <= 0 { return errors.New("decompression limit must be positive") } Try / catch
out, err := objectstore.DecompressLimit(data, objectstore.CompressionZstd, maxBytes)
if err != nil && !errors.Is(err, objectstore.ErrDecompressedTooLarge) {
return fmt.Errorf("zstd decoder setup failed, check maxBytes=%d: %w", maxBytes, err)
} Prevention
- Never pass a zero-valued int as maxBytes; apply defaults at config load.
- Reject non-positive limits in your own config validation before use.
- Pin and test the klauspost/compress version used by the library.
When it happens
Trigger: Calling Decompress/DecompressLimit with CompressionZstd where the internal zstd.NewReader(nil, WithDecoderConcurrency(1), WithDecoderMaxMemory(memoryLimit)) call returns an error — typically a non-positive or absurdly small maxBytes producing an invalid decoder memory limit.
Common situations: Passing maxBytes=0 or a negative value that slips past upstream validation; constructing DecompressLimit arguments programmatically from config where the limit is unset (0).
Understand the failure class
Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.
Related errors
- zstd read
- cave_execution_authorization_private
- caveman-code: not a file
- caveman-code: old_string and new_string are identical
- gzip read
AI-assisted analysis of JuliusBrussee/caveman@3ee70a1026 (2026-09-20).
Data as JSON: /api/errors/23ddc6324b6e856e.
Report an issue: GitHub.
Appendix: source
Thrown at shared/platform/objectstore/compress.go:102
return nil, fmt.Errorf("gzip read: %w", err)
}
if int64(len(out)) > maxBytes {
return nil, ErrDecompressedTooLarge
}
return out, nil
case CompressionZstd:
// Zstd's smallest legal window is 1 KiB. Keep that parser minimum for
// tiny valid payloads, then independently enforce the exact byte limit.
memoryLimit := uint64(maxBytes)
if memoryLimit < zstd.MinWindowSize {
memoryLimit = zstd.MinWindowSize
}
zr, err := zstd.NewReader(nil,
zstd.WithDecoderConcurrency(1),
zstd.WithDecoderMaxMemory(memoryLimit),
)
if err != nil {
return nil, fmt.Errorf("zstd reader: %w", err)
}
defer zr.Close()
out, err := zr.DecodeAll(data, nil)
if err != nil {
if errors.Is(err, zstd.ErrDecoderSizeExceeded) || errors.Is(err, zstd.ErrWindowSizeExceeded) {
return nil, ErrDecompressedTooLarge
}
return nil, fmt.Errorf("zstd read: %w", err)
}
if int64(len(out)) > maxBytes {
return nil, ErrDecompressedTooLarge
}
return out, nil
default:
return nil, fmt.Errorf("unknown compression codec %q", codec)
}
}
View on GitHub (pinned to 3ee70a1026)