cel-go
cel-go copied to clipboard
ContextEval: better error when context is canceled
Feature request checklist
- [X] There are no issues that match the desired change
- [X] The change is large enough it can't be addressed with a simple Pull Request
- [X] If this is a bug, please file a Bug Report.
Change
When ContextEval aborts evaluation because the context is canceled, it returns an error with "operation interrupted" without wrapping the ctx.Err() or (even better) the context.Cause(ctx). The caller than has to figure out via string comparisons whether the actual root cause was context cancellation and add back the cause.
Example
result, details, err := c.Program.ContextEval(ctx, variables)
if err != nil {
// Informative error wrapping the cancellation cause returned here.
return false, details, err
}
Alternatives considered
result, details, err := c.Program.ContextEval(ctx, variables)
if err != nil {
// CEL does not wrap the context error. We have to deduce why it failed.
if strings.Contains(err.Error(), "operation interrupted") && ctx.Err() != nil {
return false, details, fmt.Errorf("%w: %w", err, context.Cause(ctx))
}
return false, details, err
}
cc @jpbetz @cici37 @TristonianJones for visibility