Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 0 additions & 7 deletions common/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,6 @@ java_library(
exports = ["//common/src/main/java/dev/cel/common:mutable_source"],
)

java_library(
name = "runtime_exception",
# used_by_android
visibility = ["//:internal"],
exports = ["//common/src/main/java/dev/cel/common:runtime_exception"],
)

java_library(
name = "proto_json_adapter",
exports = ["//common/src/main/java/dev/cel/common:proto_json_adapter"],
Expand Down
48 changes: 48 additions & 0 deletions common/exceptions/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
load("@rules_java//java:defs.bzl", "java_library")

package(
default_applicable_licenses = ["//:license"],
default_visibility = ["//:internal"],
)

java_library(
name = "runtime_exception",
# used_by_android
exports = ["//common/src/main/java/dev/cel/common/exceptions:runtime_exception"],
)

java_library(
name = "attribute_not_found",
# used_by_android
exports = ["//common/src/main/java/dev/cel/common/exceptions:attribute_not_found"],
)

java_library(
name = "divide_by_zero",
# used_by_android
exports = ["//common/src/main/java/dev/cel/common/exceptions:divide_by_zero"],
)

java_library(
name = "index_out_of_bounds",
# used_by_android
exports = ["//common/src/main/java/dev/cel/common/exceptions:index_out_of_bounds"],
)

java_library(
name = "bad_format",
# used_by_android
exports = ["//common/src/main/java/dev/cel/common/exceptions:bad_format"],
)

java_library(
name = "numeric_overflow",
# used_by_android
exports = ["//common/src/main/java/dev/cel/common/exceptions:numeric_overflow"],
)

java_library(
name = "invalid_argument",
# used_by_android
exports = ["//common/src/main/java/dev/cel/common/exceptions:invalid_argument"],
)
19 changes: 1 addition & 18 deletions common/src/main/java/dev/cel/common/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -172,18 +172,6 @@ java_library(
],
)

java_library(
name = "runtime_exception",
srcs = ["CelRuntimeException.java"],
# used_by_android
tags = [
],
deps = [
":error_codes",
"//common/annotations",
],
)

java_library(
name = "mutable_ast",
srcs = ["CelMutableAst.java"],
Expand All @@ -205,7 +193,6 @@ java_library(
],
deps = [
":cel_source",
"//:auto_value",
"//common/ast:mutable_expr",
"@maven//:com_google_errorprone_error_prone_annotations",
"@maven//:com_google_guava_guava",
Expand Down Expand Up @@ -249,7 +236,6 @@ java_library(
":source",
":source_location",
"//:auto_value",
"//common/annotations",
"//common/ast",
"//common/internal",
"@maven//:com_google_errorprone_error_prone_annotations",
Expand Down Expand Up @@ -360,8 +346,5 @@ java_library(
srcs = ["Operator.java"],
tags = [
],
deps = [
"//common/ast",
"@maven//:com_google_guava_guava",
],
deps = ["@maven//:com_google_guava_guava"],
)
5 changes: 0 additions & 5 deletions common/src/main/java/dev/cel/common/CelException.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,6 @@ public CelException(String message, Throwable cause) {
super(message, cause);
}

public CelException(String message, CelErrorCode errorCode) {
super(message);
this.errorCode = errorCode;
}

public CelException(String message, Throwable cause, CelErrorCode errorCode) {
super(message, cause);
this.errorCode = errorCode;
Expand Down
99 changes: 99 additions & 0 deletions common/src/main/java/dev/cel/common/exceptions/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
load("@rules_java//java:defs.bzl", "java_library")

package(
default_applicable_licenses = ["//:license"],
default_visibility = [
"//common/exceptions:__pkg__",
"//publish:__pkg__",
],
)

java_library(
name = "runtime_exception",
srcs = ["CelRuntimeException.java"],
# used_by_android
tags = [
],
deps = [
"//common:error_codes",
"//common/annotations",
],
)

java_library(
name = "attribute_not_found",
srcs = ["CelAttributeNotFoundException.java"],
# used_by_android
tags = [
],
deps = [
"//common:error_codes",
"//common/annotations",
"//common/exceptions:runtime_exception",
],
)

java_library(
name = "divide_by_zero",
srcs = ["CelDivideByZeroException.java"],
# used_by_android
tags = [
],
deps = [
"//common:error_codes",
"//common/annotations",
"//common/exceptions:runtime_exception",
],
)

java_library(
name = "index_out_of_bounds",
srcs = ["CelIndexOutOfBoundsException.java"],
# used_by_android
tags = [
],
deps = [
"//common:error_codes",
"//common/annotations",
"//common/exceptions:runtime_exception",
],
)

java_library(
name = "bad_format",
srcs = ["CelBadFormatException.java"],
# used_by_android
tags = [
],
deps = [
"//common:error_codes",
"//common/annotations",
"//common/exceptions:runtime_exception",
],
)

java_library(
name = "numeric_overflow",
srcs = ["CelNumericOverflowException.java"],
# used_by_android
tags = [
],
deps = [
"//common:error_codes",
"//common/annotations",
"//common/exceptions:runtime_exception",
],
)

java_library(
name = "invalid_argument",
srcs = ["CelInvalidArgumentException.java"],
# used_by_android
tags = [
],
deps = [
"//common:error_codes",
"//common/annotations",
"//common/exceptions:runtime_exception",
],
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
// Copyright 2025 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package dev.cel.common.exceptions;

import dev.cel.common.CelErrorCode;
import dev.cel.common.annotations.Internal;
import java.util.Arrays;
import java.util.Collection;

/** Indicates an attempt to access a map or object using an invalid attribute or key. */
@Internal
public final class CelAttributeNotFoundException extends CelRuntimeException {

public static CelAttributeNotFoundException of(String message) {
return new CelAttributeNotFoundException(message);
}

public static CelAttributeNotFoundException forMissingMapKey(String key) {
return new CelAttributeNotFoundException(String.format("key '%s' is not present in map.", key));
}

public static CelAttributeNotFoundException forFieldResolution(String... fields) {
return forFieldResolution(Arrays.asList(fields));
}

public static CelAttributeNotFoundException forFieldResolution(Collection<String> fields) {
return new CelAttributeNotFoundException(formatErrorMessage(fields));
}

private static String formatErrorMessage(Collection<String> fields) {
String maybePlural = "";
if (fields.size() > 1) {
maybePlural = "s";
}

return String.format(
"Error resolving field%s '%s'. Field selections must be performed on messages or maps.",
maybePlural, String.join(", ", fields));
}

private CelAttributeNotFoundException(String message) {
super(message, CelErrorCode.ATTRIBUTE_NOT_FOUND);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// Copyright 2025 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package dev.cel.common.exceptions;

import dev.cel.common.CelErrorCode;
import dev.cel.common.annotations.Internal;

/** Indicates that a data conversion failed due to a mismatch in the format specification. */
@Internal
public final class CelBadFormatException extends CelRuntimeException {

public CelBadFormatException(Throwable cause) {
super(cause, CelErrorCode.BAD_FORMAT);
}

public CelBadFormatException(String errorMessage) {
super(errorMessage, CelErrorCode.BAD_FORMAT);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,20 @@
// See the License for the specific language governing permissions and
// limitations under the License.

package dev.cel.runtime.standard;
package dev.cel.common.exceptions;

import dev.cel.common.CelErrorCode;
import dev.cel.common.annotations.Internal;

final class ArithmeticHelpers {
/** Indicates that a division by zero occurred. */
@Internal
public final class CelDivideByZeroException extends CelRuntimeException {

static CelErrorCode getArithmeticErrorCode(ArithmeticException e) {
String exceptionMessage = e.getMessage();
// The two known cases for an arithmetic exception is divide by zero and overflow.
if (exceptionMessage.equals("/ by zero")) {
return CelErrorCode.DIVIDE_BY_ZERO;
}
return CelErrorCode.NUMERIC_OVERFLOW;
public CelDivideByZeroException() {
super("/ by zero", CelErrorCode.DIVIDE_BY_ZERO);
}

private ArithmeticHelpers() {}
public CelDivideByZeroException(Throwable cause) {
super(cause, CelErrorCode.DIVIDE_BY_ZERO);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// Copyright 2025 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package dev.cel.common.exceptions;

import dev.cel.common.CelErrorCode;
import dev.cel.common.annotations.Internal;

/** Indicates that a list index access was attempted using an index that is out of bounds. */
@Internal
public final class CelIndexOutOfBoundsException extends CelRuntimeException {

public CelIndexOutOfBoundsException(Object index) {
super("Index out of bounds: " + index, CelErrorCode.INDEX_OUT_OF_BOUNDS);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// Copyright 2025 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package dev.cel.common.exceptions;

import dev.cel.common.CelErrorCode;
import dev.cel.common.annotations.Internal;

/** Indicates that an invalid argument was supplied to a function. */
@Internal
public final class CelInvalidArgumentException extends CelRuntimeException {

public CelInvalidArgumentException(Throwable cause) {
super(cause, CelErrorCode.INVALID_ARGUMENT);
}
}
Loading