Skip to content

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.

1 / 0
// error: division by zero

Avoid this error by checking the divisor first.

// input: x = 0
x != 0 ? 1 / x : 0
// result: 0 (int)
// input: x = 0
x == 0 || 100 / x > 2
// result: true (bool)

Index out of bounds#

Accessing a list index beyond its size produces an error.

[1, 2, 3][10]
// error: index out of bounds: 10

Avoid this error by checking the index is within bounds.

// input: items = [1, 2, 3], i = 10
i >= 0 && i < items.size() ? items[i] : 0
// result: 0 (int)

Missing map keys#

Accessing a map key that does not exist produces an error.

{"a": 1}["b"]
// error: no such key: b

Avoid this error with the in operator.

// input: data = {"a": 1}
"b" in data ? data["b"] : 0
// result: 0 (int)

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#