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
2 changes: 1 addition & 1 deletion runtime/src/main/java/dev/cel/runtime/Activation.java
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ public static Activation fromProto(Message message, CelOptions celOptions) {
} catch (IllegalArgumentException e) {
variables.put(
field.getName(),
new InterpreterException.Builder(
CelEvaluationExceptionBuilder.newBuilder(
"illegal field value. field=%s, value=%s", field.getName(), fieldValue)
.setCause(e)
.build());
Expand Down
8 changes: 6 additions & 2 deletions runtime/src/main/java/dev/cel/runtime/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ java_library(
tags = [
],
deps = [
":evaluation_exception",
":metadata",
"//:auto_value",
"//common",
Expand All @@ -80,6 +81,8 @@ java_library(
deps = [
":base",
":cel_type_resolver",
":evaluation_exception",
":evaluation_exception_builder",
":evaluation_listener",
":metadata",
":runtime_helper",
Expand Down Expand Up @@ -197,7 +200,6 @@ java_library(
],
deps = [
":evaluation_exception",
":evaluation_exception_builder",
":evaluation_listener",
":runtime_helper",
":runtime_type_provider_legacy",
Expand All @@ -206,12 +208,14 @@ java_library(
"//common",
"//common:error_codes",
"//common:options",
"//common:runtime_exception",
"//common/annotations",
"//common/internal:cel_descriptor_pools",
"//common/internal:comparison_functions",
"//common/internal:default_message_factory",
"//common/internal:dynamic_proto",
"//common/internal:proto_message_factory",
"//common/internal:safe_string_formatter",
"//common/types:cel_types",
"//common/values:cel_value_provider",
"//common/values:proto_message_value_provider",
Expand Down Expand Up @@ -295,9 +299,9 @@ java_library(
tags = [
],
deps = [
":base",
":unknown_attributes",
"//common/annotations",
"//runtime",
"@maven//:com_google_errorprone_error_prone_annotations",
"@maven//:org_jspecify_jspecify",
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

import com.google.common.collect.ImmutableMap;
import com.google.errorprone.annotations.Immutable;
import dev.cel.common.CelException;
import java.util.Arrays;
import java.util.List;
import java.util.Optional;
Expand All @@ -38,7 +37,7 @@ private CelLateFunctionBindings(ImmutableMap<String, ResolvedOverload> functions

@Override
public Optional<ResolvedOverload> findOverload(
String functionName, List<String> overloadIds, Object[] args) throws CelException {
String functionName, List<String> overloadIds, Object[] args) throws CelEvaluationException {
return DefaultDispatcher.findOverload(functionName, overloadIds, functions, args);
}

Expand All @@ -59,12 +58,6 @@ private static ResolvedOverload createResolvedOverload(CelRuntime.CelFunctionBin
return CelResolvedOverload.of(
binding.getOverloadId(),
binding.getArgTypes(),
(args) -> {
try {
return binding.getDefinition().apply(args);
} catch (CelException e) {
throw InterpreterException.wrapOrThrow(e);
}
});
(args) -> binding.getDefinition().apply(args));
}
}
53 changes: 19 additions & 34 deletions runtime/src/main/java/dev/cel/runtime/CelRuntime.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableList;
import com.google.errorprone.annotations.CanIgnoreReturnValue;
import com.google.errorprone.annotations.CheckReturnValue;
import com.google.errorprone.annotations.Immutable;
import javax.annotation.concurrent.ThreadSafe;
import com.google.protobuf.Message;
Expand Down Expand Up @@ -192,30 +191,26 @@ private Object evalInternal(
Optional<CelFunctionResolver> lateBoundFunctionResolver,
CelEvaluationListener listener)
throws CelEvaluationException {
try {
Interpretable impl = getInterpretable();
if (getOptions().enableUnknownTracking()) {
Preconditions.checkState(
impl instanceof UnknownTrackingInterpretable,
"Environment misconfigured. Requested unknown tracking without a compatible"
+ " implementation.");

UnknownTrackingInterpretable interpreter = (UnknownTrackingInterpretable) impl;
return interpreter.evalTrackingUnknowns(
RuntimeUnknownResolver.builder()
.setResolver(context.variableResolver())
.setAttributeResolver(context.createAttributeResolver())
.build(),
lateBoundFunctionResolver,
listener);
} else {
if (lateBoundFunctionResolver.isPresent()) {
return impl.eval(context.variableResolver(), lateBoundFunctionResolver.get(), listener);
}
return impl.eval(context.variableResolver(), listener);
Interpretable impl = getInterpretable();
if (getOptions().enableUnknownTracking()) {
Preconditions.checkState(
impl instanceof UnknownTrackingInterpretable,
"Environment misconfigured. Requested unknown tracking without a compatible"
+ " implementation.");

UnknownTrackingInterpretable interpreter = (UnknownTrackingInterpretable) impl;
return interpreter.evalTrackingUnknowns(
RuntimeUnknownResolver.builder()
.setResolver(context.variableResolver())
.setAttributeResolver(context.createAttributeResolver())
.build(),
lateBoundFunctionResolver,
listener);
} else {
if (lateBoundFunctionResolver.isPresent()) {
return impl.eval(context.variableResolver(), lateBoundFunctionResolver.get(), listener);
}
} catch (InterpreterException e) {
throw unwrapOrCreateEvaluationException(e);
return impl.eval(context.variableResolver(), listener);
}
}

Expand All @@ -229,16 +224,6 @@ private Object evalInternal(
static Program from(Interpretable interpretable, CelOptions options) {
return new AutoValue_CelRuntime_Program(interpretable, options);
}

@CheckReturnValue
private static CelEvaluationException unwrapOrCreateEvaluationException(
InterpreterException e) {
if (e.getCause() instanceof CelEvaluationException) {
return (CelEvaluationException) e.getCause();
}

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

/**
Expand Down
13 changes: 1 addition & 12 deletions runtime/src/main/java/dev/cel/runtime/CelRuntimeLegacyImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -257,18 +257,7 @@ public CelRuntimeLegacyImpl build() {
.forEach(
(String overloadId, CelFunctionBinding func) ->
dispatcher.add(
overloadId,
func.getArgTypes(),
(args) -> {
try {
return func.getDefinition().apply(args);
} catch (CelEvaluationException e) {
throw new InterpreterException.Builder(e.getMessage())
.setCause(e)
.setErrorCode(e.getErrorCode())
.build();
}
}));
overloadId, func.getArgTypes(), (args) -> func.getDefinition().apply(args)));

RuntimeTypeProvider runtimeTypeProvider;

Expand Down
Loading