Skip to content
Merged
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
6 changes: 6 additions & 0 deletions common/exceptions/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ package(
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
Expand Down
12 changes: 0 additions & 12 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 Down
26 changes: 19 additions & 7 deletions common/src/main/java/dev/cel/common/exceptions/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,27 @@ package(
],
)

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 = [
":runtime_exception",
"//common:error_codes",
"//common:runtime_exception",
"//common/annotations",
],
)
Expand All @@ -28,8 +40,8 @@ java_library(
tags = [
],
deps = [
":runtime_exception",
"//common:error_codes",
"//common:runtime_exception",
"//common/annotations",
],
)
Expand All @@ -41,8 +53,8 @@ java_library(
tags = [
],
deps = [
":runtime_exception",
"//common:error_codes",
"//common:runtime_exception",
"//common/annotations",
],
)
Expand All @@ -54,8 +66,8 @@ java_library(
tags = [
],
deps = [
":runtime_exception",
"//common:error_codes",
"//common:runtime_exception",
"//common/annotations",
],
)
Expand All @@ -67,8 +79,8 @@ java_library(
tags = [
],
deps = [
":runtime_exception",
"//common:error_codes",
"//common:runtime_exception",
"//common/annotations",
],
)
Expand All @@ -80,8 +92,8 @@ java_library(
tags = [
],
deps = [
":runtime_exception",
"//common:error_codes",
"//common:runtime_exception",
"//common/annotations",
],
)
Expand All @@ -93,8 +105,8 @@ java_library(
tags = [
],
deps = [
":runtime_exception",
"//common:error_codes",
"//common:runtime_exception",
"//common/annotations",
],
)
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
package dev.cel.common.exceptions;

import dev.cel.common.CelErrorCode;
import dev.cel.common.CelRuntimeException;
import dev.cel.common.annotations.Internal;
import java.util.Arrays;
import java.util.Collection;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
package dev.cel.common.exceptions;

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

/** Indicates that a data conversion failed due to a mismatch in the format specification. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
package dev.cel.common.exceptions;

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

/** Indicates that a division by zero occurred. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
package dev.cel.common.exceptions;

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

/** Indicates that a list index access was attempted using an index that is out of bounds. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
package dev.cel.common.exceptions;

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

/** Indicates that an invalid argument was supplied to a function. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
package dev.cel.common.exceptions;

import dev.cel.common.CelErrorCode;
import dev.cel.common.CelRuntimeException;
import dev.cel.common.annotations.Internal;
import java.util.Locale;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
package dev.cel.common.exceptions;

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

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,22 @@
// See the License for the specific language governing permissions and
// limitations under the License.

package dev.cel.common;
package dev.cel.common.exceptions;

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

/**
* Wrapper for an unchecked runtime exception with a CelErrorCode supplied.
*
* <p>Note: This is not to be confused with the notion of CEL Runtime. Use {@code
* CelEvaluationException} instead to signify an evaluation error. corresponds to the CelErrorCode.
* CelEvaluationException} instead to signify an evaluation error.
*/
@Internal
public class CelRuntimeException extends RuntimeException {
public abstract class CelRuntimeException extends RuntimeException {
private final CelErrorCode errorCode;

public CelRuntimeException(String errorMessage, CelErrorCode errorCode) {
CelRuntimeException(String errorMessage, CelErrorCode errorCode) {
super(errorMessage);
this.errorCode = errorCode;
}
Expand Down
13 changes: 4 additions & 9 deletions common/src/main/java/dev/cel/common/internal/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -173,11 +173,9 @@ java_library(
":proto_lite_adapter",
":proto_message_factory",
":well_known_proto",
"//:auto_value",
"//common:error_codes",
"//common:options",
"//common:runtime_exception",
"//common/annotations",
"//common/exceptions:numeric_overflow",
"//common/values",
"//common/values:cel_byte_string",
"@maven//:com_google_code_findbugs_annotations",
Expand All @@ -194,11 +192,10 @@ java_library(
],
deps = [
":well_known_proto",
"//common:error_codes",
"//common:options",
"//common:proto_json_adapter",
"//common:runtime_exception",
"//common/annotations",
"//common/exceptions:numeric_overflow",
"//common/internal:proto_time_utils",
"//common/values",
"//common/values:cel_byte_string",
Expand Down Expand Up @@ -441,9 +438,8 @@ java_library(
tags = [
],
deps = [
"//common:error_codes",
"//common:runtime_exception",
"//common/annotations",
"//common/exceptions:bad_format",
"@maven//:com_google_guava_guava",
"@maven//:com_google_protobuf_protobuf_java",
],
Expand All @@ -455,9 +451,8 @@ cel_android_library(
tags = [
],
deps = [
"//common:error_codes",
"//common:runtime_exception",
"//common/annotations",
"//common/exceptions:bad_format",
"@maven_android//:com_google_guava_guava",
"@maven_android//:com_google_protobuf_protobuf_javalite",
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,8 @@

import com.google.common.base.Strings;
import com.google.protobuf.Timestamp;
import dev.cel.common.CelErrorCode;
import dev.cel.common.CelRuntimeException;
import dev.cel.common.annotations.Internal;
import dev.cel.common.exceptions.CelBadFormatException;
import java.time.DateTimeException;
import java.time.Duration;
import java.time.Instant;
Expand Down Expand Up @@ -184,7 +183,7 @@ private static ZoneId timeZone(String tz) {
try {
int ind = tz.indexOf(":");
if (ind == -1) {
throw new CelRuntimeException(e, CelErrorCode.BAD_FORMAT);
throw new CelBadFormatException(e);
}

int hourOffset = Integer.parseInt(tz.substring(0, ind));
Expand All @@ -199,7 +198,7 @@ private static ZoneId timeZone(String tz) {
return ZoneId.of(formattedOffset);

} catch (DateTimeException e2) {
throw new CelRuntimeException(e2, CelErrorCode.BAD_FORMAT);
throw new CelBadFormatException(e2);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,9 @@
import com.google.protobuf.MapEntry;
import com.google.protobuf.Message;
import com.google.protobuf.MessageOrBuilder;
import dev.cel.common.CelErrorCode;
import dev.cel.common.CelOptions;
import dev.cel.common.CelRuntimeException;
import dev.cel.common.annotations.Internal;
import dev.cel.common.exceptions.CelNumericOverflowException;
import dev.cel.common.values.CelByteString;
import dev.cel.common.values.NullValue;
import java.util.ArrayList;
Expand Down Expand Up @@ -361,15 +360,15 @@ private static int intCheckedCast(long value) {
try {
return Ints.checkedCast(value);
} catch (IllegalArgumentException e) {
throw new CelRuntimeException(e, CelErrorCode.NUMERIC_OVERFLOW);
throw new CelNumericOverflowException(e);
}
}

private static int unsignedIntCheckedCast(long value) {
try {
return UnsignedInts.checkedCast(value);
} catch (IllegalArgumentException e) {
throw new CelRuntimeException(e, CelErrorCode.NUMERIC_OVERFLOW);
throw new CelNumericOverflowException(e);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,10 @@
import com.google.protobuf.UInt32Value;
import com.google.protobuf.UInt64Value;
import com.google.protobuf.Value;
import dev.cel.common.CelErrorCode;
import dev.cel.common.CelOptions;
import dev.cel.common.CelProtoJsonAdapter;
import dev.cel.common.CelRuntimeException;
import dev.cel.common.annotations.Internal;
import dev.cel.common.exceptions.CelNumericOverflowException;
import dev.cel.common.values.CelByteString;
import java.time.Instant;
import java.util.Map;
Expand Down Expand Up @@ -284,14 +283,14 @@ private Message adaptValueToUint32(Object value) {
try {
return UInt32Value.of(unsignedIntCheckedCast((Long) value));
} catch (IllegalArgumentException e) {
throw new CelRuntimeException(e, CelErrorCode.NUMERIC_OVERFLOW);
throw new CelNumericOverflowException(e);
}
}
if (value instanceof UnsignedLong) {
try {
return UInt32Value.of(unsignedIntCheckedCast(((UnsignedLong) value).longValue()));
} catch (IllegalArgumentException e) {
throw new CelRuntimeException(e, CelErrorCode.NUMERIC_OVERFLOW);
throw new CelNumericOverflowException(e);
}
}

Expand All @@ -316,15 +315,15 @@ private static int intCheckedCast(long value) {
try {
return Ints.checkedCast(value);
} catch (IllegalArgumentException e) {
throw new CelRuntimeException(e, CelErrorCode.NUMERIC_OVERFLOW);
throw new CelNumericOverflowException(e);
}
}

private static int unsignedIntCheckedCast(long value) {
try {
return UnsignedInts.checkedCast(value);
} catch (IllegalArgumentException e) {
throw new CelRuntimeException(e, CelErrorCode.NUMERIC_OVERFLOW);
throw new CelNumericOverflowException(e);
}
}

Expand Down
1 change: 1 addition & 0 deletions extensions/src/main/java/dev/cel/extensions/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ java_library(
"//common:compiler_common",
"//common:options",
"//common/ast",
"//common/exceptions:numeric_overflow",
"//common/internal:comparison_functions",
"//common/types",
"//compiler:compiler_builder",
Expand Down
Loading
Loading