Skip to content

Commit

Permalink
Split CelEvaluationException from runtime build target
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 715998045
  • Loading branch information
l46kok authored and copybara-github committed Jan 16, 2025
1 parent 4a47e75 commit d107359
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 10 deletions.
5 changes: 4 additions & 1 deletion runtime/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@ package(

java_library(
name = "runtime",
exports = ["//runtime/src/main/java/dev/cel/runtime"],
exports = [
"//runtime/src/main/java/dev/cel/runtime",
"//runtime/src/main/java/dev/cel/runtime:evaluation_exception",
],
)

java_library(
Expand Down
14 changes: 12 additions & 2 deletions runtime/src/main/java/dev/cel/runtime/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,6 @@ java_library(

# keep sorted
RUNTIME_SOURCES = [
"CelEvaluationException.java",
"CelFunctionOverload.java",
"CelFunctionResolver.java",
"CelLateFunctionBindings.java",
Expand All @@ -157,12 +156,24 @@ RUNTIME_SOURCES = [
"UnknownContext.java",
]

java_library(
name = "evaluation_exception",
srcs = ["CelEvaluationException.java"],
tags = [
],
deps = [
"//common",
"//common:error_codes",
],
)

java_library(
name = "runtime",
srcs = RUNTIME_SOURCES,
tags = [
],
deps = [
":evaluation_exception",
":evaluation_listener",
":runtime_helper",
":runtime_type_provider_legacy",
Expand All @@ -186,7 +197,6 @@ java_library(
"@maven//:com_google_guava_guava",
"@maven//:com_google_protobuf_protobuf_java",
"@maven//:com_google_protobuf_protobuf_java_util",
"@maven//:com_google_re2j_re2j",
"@maven//:org_jspecify_jspecify",
],
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,17 @@ public CelEvaluationException(String message, Throwable cause) {
super(formatErrorMessage(message), cause);
}

public CelEvaluationException(String message, Throwable cause, CelErrorCode errorCode) {
super(formatErrorMessage(message), cause, errorCode);
}

public CelEvaluationException(String message, CelErrorCode errorCode) {
super(formatErrorMessage(message), errorCode);
}

CelEvaluationException(InterpreterException cause, CelErrorCode errorCode) {
super(cause.getMessage(), cause.getCause(), errorCode);
public CelEvaluationException(String message, Throwable cause, CelErrorCode errorCode) {
this(message, cause, errorCode, true);
}

CelEvaluationException(
String message, Throwable cause, CelErrorCode errorCode, boolean formatErrorMessage) {
super(formatErrorMessage ? formatErrorMessage(message) : message, cause, errorCode);
}

private static String formatErrorMessage(String message) {
Expand Down
3 changes: 2 additions & 1 deletion runtime/src/main/java/dev/cel/runtime/CelRuntime.java
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,8 @@ private static CelEvaluationException unwrapOrCreateEvaluationException(
if (e.getCause() instanceof CelEvaluationException) {
return (CelEvaluationException) e.getCause();
}
return new CelEvaluationException(e, e.getErrorCode());

return new CelEvaluationException(e.getMessage(), e.getCause(), e.getErrorCode(), false);
}
}

Expand Down

0 comments on commit d107359

Please sign in to comment.