Skip to content

Commit

Permalink
Internal Changes
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 719018236
  • Loading branch information
l46kok authored and copybara-github committed Jan 25, 2025
1 parent 1ac9c4b commit 017a4fe
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 0 deletions.
1 change: 1 addition & 0 deletions runtime/src/main/java/dev/cel/runtime/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ java_library(
":evaluation_exception",
":metadata",
"//common:error_codes",
"//common:runtime_exception",
"//common/annotations",
"//common/internal:safe_string_formatter",
"@maven//:com_google_errorprone_error_prone_annotations",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

import com.google.errorprone.annotations.CanIgnoreReturnValue;
import dev.cel.common.CelErrorCode;
import dev.cel.common.CelRuntimeException;
import dev.cel.common.annotations.Internal;
import dev.cel.common.internal.SafeStringFormatter;
import org.jspecify.annotations.Nullable;
Expand Down Expand Up @@ -74,6 +75,19 @@ public static CelEvaluationExceptionBuilder newBuilder(String message, Object...
return new CelEvaluationExceptionBuilder(SafeStringFormatter.format(message, args));
}

/**
* Constructs a new builder for {@link CelEvaluationException}
*
* <p>CEL Library Internals. Do not use.
*/
@Internal
public static CelEvaluationExceptionBuilder newBuilder(CelRuntimeException celRuntimeException) {
Throwable cause = celRuntimeException.getCause();
return new CelEvaluationExceptionBuilder(cause.getMessage())
.setCause(cause)
.setErrorCode(celRuntimeException.getErrorCode());
}

private CelEvaluationExceptionBuilder(String message) {
this.message = message;
this.errorCode = CelErrorCode.INTERNAL_ERROR;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import com.google.testing.junit.testparameterinjector.TestParameterInjector;
import dev.cel.common.CelErrorCode;
import dev.cel.common.CelRuntimeException;
import org.junit.Test;
import org.junit.runner.RunWith;

Expand Down Expand Up @@ -77,4 +78,19 @@ public int getPosition(long exprId) {
assertThat(e).hasCauseThat().isEqualTo(cause);
assertThat(e.getErrorCode()).isEqualTo(CelErrorCode.BAD_FORMAT);
}

@Test
public void builder_fromCelRuntimeException() {
IllegalStateException cause = new IllegalStateException("cause error message");
CelRuntimeException celRuntimeException =
new CelRuntimeException(cause, CelErrorCode.BAD_FORMAT);
CelEvaluationExceptionBuilder builder =
CelEvaluationExceptionBuilder.newBuilder(celRuntimeException);

CelEvaluationException e = builder.build();

assertThat(e).hasMessageThat().isEqualTo("evaluation error: cause error message");
assertThat(e).hasCauseThat().isEqualTo(cause);
assertThat(e.getErrorCode()).isEqualTo(CelErrorCode.BAD_FORMAT);
}
}

0 comments on commit 017a4fe

Please sign in to comment.