Fix error message for missing attribute by copybara-service[bot] · Pull Request #962 · cel-expr/cel-java · GitHub
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
Original file line number Diff line number Diff line change
Expand Up @@ -22,26 +22,44 @@
final class MissingAttribute implements Attribute {

private final ImmutableSet<String> missingAttributes;
private final Kind kind;

@Override
public Object resolve(GlobalResolver ctx, ExecutionFrame frame) {
throw CelAttributeNotFoundException.forFieldResolution(missingAttributes);
switch (kind) {
case ATTRIBUTE_NOT_FOUND:
throw CelAttributeNotFoundException.forMissingAttributes(missingAttributes);
case FIELD_NOT_FOUND:
throw CelAttributeNotFoundException.forFieldResolution(missingAttributes);
}

throw new IllegalArgumentException("Unexpected kind: " + kind);
}

@Override
public Attribute addQualifier(Qualifier qualifier) {
throw new UnsupportedOperationException("Unsupported operation");
}

static MissingAttribute newMissingAttribute(String... attributeNames) {
return newMissingAttribute(ImmutableSet.copyOf(attributeNames));
static MissingAttribute newMissingAttribute(ImmutableSet<String> attributeNames) {
return new MissingAttribute(attributeNames, Kind.ATTRIBUTE_NOT_FOUND);
}

static MissingAttribute newMissingAttribute(ImmutableSet<String> attributeNames) {
return new MissingAttribute(attributeNames);
static MissingAttribute newMissingField(String... attributeNames) {
return newMissingField(ImmutableSet.copyOf(attributeNames));
}

private MissingAttribute(ImmutableSet<String> missingAttributes) {
static MissingAttribute newMissingField(ImmutableSet<String> attributeNames) {
return new MissingAttribute(attributeNames, Kind.FIELD_NOT_FOUND);
}

private MissingAttribute(ImmutableSet<String> missingAttributes, Kind kind) {
this.missingAttributes = missingAttributes;
this.kind = kind;
}

private enum Kind {
ATTRIBUTE_NOT_FOUND,
FIELD_NOT_FOUND
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

package dev.cel.runtime.planner;

import static dev.cel.runtime.planner.MissingAttribute.newMissingAttribute;
import static dev.cel.runtime.planner.MissingAttribute.newMissingField;

import dev.cel.common.values.SelectableValue;
import java.util.Map;
Expand All @@ -40,7 +40,7 @@ public Object qualify(Object obj) {
return map.containsKey(value);
}

return newMissingAttribute(value.toString());
return newMissingField(value.toString());
}

static PresenceTestQualifier create(Object value) {
Expand Down
Loading