Common errors#
CEL expressions can produce runtime errors. Errors propagate through expressions unless short-circuit evaluation avoids them.
Division by zero#
Integer division by zero produces an error.
Avoid this error by checking the divisor first.
Index out of bounds#
Accessing a list index beyond its size produces an error.
Avoid this error by checking the index is within bounds.
Missing map keys#
Accessing a map key that does not exist produces an error.
Avoid this error with the in operator.
Null wrapper values#
Protobuf wrapper types return null when unset.
Using a null value in an operation produces an error.
// input: user = example.v1.User{name: "Alice"}
user.nickname + " (nickname)"
// error: no such overload: _+_
Avoid this error with the has() macro.
// input: user = example.v1.User{name: "Alice"}
has(user.nickname) ? user.nickname : "none"
// result: "none" (string)
See also#
- Logical operators - Short-circuit evaluation
- Conditional operator - Conditional expressions
- Has - Field presence testing