From 913d5813a9fdee622c7d84fb8f37077db2b11d9f Mon Sep 17 00:00:00 2001 From: Davanum Srinivas Date: Sun, 12 Apr 2026 17:50:49 -0400 Subject: [PATCH] Preserve operation interrupted in ContextEval error When ContextEval detects an InterruptError, wrap both the original error and the context cause using fmt.Errorf("%w: %w", ...) so that: - errors.Is(err, context.Canceled) works (new behavior) - errors.Is(err, context.DeadlineExceeded) works (new behavior) - errors.Is(err, InterruptError{}) works (preserved) - strings.Contains(err.Error(), "operation interrupted") works (backward compat) Previously, the error was replaced entirely with context.Cause(ctx), which dropped the "operation interrupted" message that downstream consumers (e.g. Kubernetes) rely on for string matching. Fixes #1195 while maintaining backward compatibility. Signed-off-by: Davanum Srinivas --- cel/cel_test.go | 5 ++++- cel/program.go | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/cel/cel_test.go b/cel/cel_test.go index 31b2a318..63098a8f 100644 --- a/cel/cel_test.go +++ b/cel/cel_test.go @@ -1160,9 +1160,12 @@ func TestContextEval(t *testing.T) { if err == nil { t.Errorf("Got result %v, wanted timeout error", out) } - if err != nil && err.Error() != "context deadline exceeded" { + if err != nil && !errors.Is(err, context.DeadlineExceeded) { t.Errorf("Got %v, wanted context deadline exceeded", err) } + if err != nil && !strings.Contains(err.Error(), "operation interrupted") { + t.Errorf("Got %v, wanted error containing 'operation interrupted'", err) + } } func TestContextEvalUnknowns(t *testing.T) { diff --git a/cel/program.go b/cel/program.go index c46d694e..c8b72504 100644 --- a/cel/program.go +++ b/cel/program.go @@ -370,7 +370,7 @@ func (p *prog) ContextEval(ctx context.Context, input any) (ref.Val, *EvalDetail } out, det, err := p.Eval(vars) if err != nil && errors.Is(err, interpreter.InterruptError{}) { - return out, det, context.Cause(ctx) + return out, det, fmt.Errorf("%w: %w", err, context.Cause(ctx)) } return out, det, err }