JuliusBrussee/caveman · error
cacheengine: nil context
Error message
cacheengine: nil context
What it means
Engine.Optimize rejects a nil context before doing any work. The guard fires when a caller (prepare or a simulated-trace evaluation) passes a literal nil ctx instead of context.Background/WithCancel; later stages rely on ctx for cancellation and tracing, so the nil is caught up front rather than panicking deep in native cache-metadata optimization. It follows separate nil-engine and stale-config-error guards.
Source
Thrown at cacheengine/native.go:26
"io"
"strconv"
"strings"
"time"
"github.com/JuliusBrussee/caveman/proxy/providers/jsonsplice"
)
// Optimize applies provider-native cache metadata or returns copied original
// bytes on every unsupported or unsafe path. It makes no network call.
func (e *Engine) Optimize(ctx context.Context, request NativeRequest) (NativeResult, error) {
if e == nil || e.guard == nil || e.prefixSafety == nil || e.resolveProfile == nil {
return NativeResult{}, errors.New("cacheengine: nil engine")
}
if e.configErr != nil {
return NativeResult{}, e.configErr
}
if ctx == nil {
return NativeResult{}, errors.New("cacheengine: nil context")
}
if err := ctx.Err(); err != nil {
return NativeResult{}, err
}
if len(request.Body) > e.maxRequestBytes {
return NativeResult{}, errors.New("cacheengine: request exceeds configured byte limit")
}
original := append([]byte(nil), request.Body...)
unsupported := Profile{ID: "unsupported", Mode: ModeUnsupported, Attribution: AttributionNone}
result := NativeResult{
Body: original,
Decision: DecisionPassThrough,
Reason: ReasonUnsupported,
Profile: unsupported,
Plan: Plan{
Decision: DecisionPassThrough, Reason: ReasonUnsupported,
ProfileID: unsupported.ID, Mode: unsupported.Mode, Attribution: unsupported.Attribution,
EconomicsBasis: "unavailable", KeyShardCount: 1,View on GitHub (pinned to 766dce6b13)
Solutions
- Pass the caller's context.Context (e.g. context.Background() at top level)
- Thread the request context through to the Optimize call
Defensive patterns
Strategy: validation
When it happens
Trigger: Thrown at cacheengine/native.go:26 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/71d6adf0719719bf.
Report an issue: GitHub.