JuliusBrussee/caveman · error
cacheengine: max key shards must be within 0..
Error message
cacheengine: max key shards must be within 0..%d
What it means
Raised by newEngine (behind New/NewChecked): Config.MaxKeyShards is negative or above maxConfiguredKeyShards. It is a construction-time bounds check so a misconfigured shard count fails immediately instead of corrupting shard routing later.
Solutions
- Set MaxKeyShards within 0..maxConfiguredKeyShards (the %d in the message)
- Leave MaxKeyShards at its zero default to accept the engine default shard count
- Use NewChecked to surface this error explicitly at construction time
Defensive patterns
Strategy: validation
When it happens
Trigger: Thrown at cacheengine/engine.go:60 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of JuliusBrussee/caveman@766dce6b13 (2026-08-18).
Data as JSON: /api/errors/b1242014c0193fdd.
Report an issue: GitHub.
Appendix: source
Thrown at cacheengine/engine.go:60
return &Engine{
guard: cacheguard.New(), prefixSafety: newPrefixSafetyCache(8192),
maxKeyShards: 64, maxRequestBytes: defaultInputByteLimit, maxStablePrefixBytes: defaultInputByteLimit,
resolveProfile: defaultProfile, drivers: map[string]Driver{}, configErr: err,
}
}
return engine
}
// NewChecked validates configuration at construction time. New preserves its
// original one-result API but stores the same configuration error and makes all
// operations fail closed.
func NewChecked(config Config) (*Engine, error) {
return newEngine(config)
}
func newEngine(config Config) (*Engine, error) {
if config.MaxKeyShards < 0 || config.MaxKeyShards > maxConfiguredKeyShards {
return nil, fmt.Errorf("cacheengine: max key shards must be within 0..%d", maxConfiguredKeyShards)
}
if config.MaxRequestBytes < 0 || config.MaxRequestBytes > maxConfiguredByteLimit {
return nil, fmt.Errorf("cacheengine: max request bytes must be within 0..%d", maxConfiguredByteLimit)
}
if config.MaxStablePrefixBytes < 0 || config.MaxStablePrefixBytes > maxConfiguredByteLimit {
return nil, fmt.Errorf("cacheengine: max stable prefix bytes must be within 0..%d", maxConfiguredByteLimit)
}
maxShards := config.MaxKeyShards
if maxShards == 0 {
maxShards = 64
}
maxRequestBytes := config.MaxRequestBytes
if maxRequestBytes == 0 {
maxRequestBytes = defaultInputByteLimit
}
maxStablePrefixBytes := config.MaxStablePrefixBytes
if maxStablePrefixBytes == 0 {
maxStablePrefixBytes = defaultInputByteLimitView on GitHub (pinned to 766dce6b13)