Skip to content

Commit

Permalink
Rename error messsage
Browse files Browse the repository at this point in the history
remote unnecessary comments and dead code
  • Loading branch information
jpbempel committed Jul 9, 2024
1 parent 8712cc2 commit 32bad46
Show file tree
Hide file tree
Showing 10 changed files with 30 additions and 86 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ public Object getMember(Object target, String memberName) {
}
target = ReflectiveFieldValueResolver.resolve(target, target.getClass(), memberName);
}
checkUndefined(target, memberName, "Cannot dereference to field: ");
checkUndefined(target, memberName, "Cannot dereference field: ");
return target;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,7 @@ class Obj1 {
private int field = 10;
List<String> field2 = new ArrayList<>();
}
ValueReferenceResolver ctx =
RefResolverHelper.createResolver(singletonMap("this", new Obj1()), null);
ValueReferenceResolver ctx = RefResolverHelper.createResolver(new Obj1());

assertTrue(probeCondition.execute(ctx));

Expand All @@ -48,8 +47,7 @@ class Obj2 {
private int field = 10;
List<String> field2 = new ArrayList<>();
}
ValueReferenceResolver ctx2 =
RefResolverHelper.createResolver(singletonMap("this", new Obj2()), null);
ValueReferenceResolver ctx2 = RefResolverHelper.createResolver(new Obj2());
assertFalse(probeCondition.execute(ctx2));
}

Expand All @@ -72,7 +70,7 @@ class Obj2 {
singletonMap("this", new Obj2()), singletonMap("container", new Container("world")));
RuntimeException runtimeException =
assertThrows(RuntimeException.class, () -> probeCondition.execute(ctx2));
assertEquals("Cannot dereference to field: container", runtimeException.getMessage());
assertEquals("Cannot dereference field: container", runtimeException.getMessage());
}

@Test
Expand All @@ -82,8 +80,7 @@ class Obj {
int intField1 = 42;
String strField = "foo";
}
Obj obj = new Obj();
ValueReferenceResolver ctx = RefResolverHelper.createResolver(singletonMap("this", obj), null);
ValueReferenceResolver ctx = RefResolverHelper.createResolver(new Obj());
assertTrue(probeCondition.execute(ctx));
}

Expand Down Expand Up @@ -115,8 +112,7 @@ class Obj {

int idx = 1;
}
ValueReferenceResolver ctx =
RefResolverHelper.createResolver(singletonMap("this", new Obj()), null);
ValueReferenceResolver ctx = RefResolverHelper.createResolver(new Obj());
assertTrue(probeCondition.execute(ctx));
}

Expand All @@ -126,8 +122,7 @@ void testStringOperation() throws Exception {
class Obj {
String strField = "foobar";
}
ValueReferenceResolver ctx =
RefResolverHelper.createResolver(singletonMap("this", new Obj()), null);
ValueReferenceResolver ctx = RefResolverHelper.createResolver(new Obj());
assertTrue(probeCondition.execute(ctx));
}

Expand All @@ -149,8 +144,7 @@ void testJsonParsing() throws IOException {
class Obj {
Collection<String> vets = Arrays.asList("vet1", "vet2", "vet3");
}
ValueReferenceResolver ctx =
RefResolverHelper.createResolver(singletonMap("this", new Obj()), null);
ValueReferenceResolver ctx = RefResolverHelper.createResolver(new Obj());

// the condition checks if length of vets > 2
assertTrue(probeCondition.execute(ctx));
Expand Down Expand Up @@ -222,8 +216,7 @@ class Obj {
Set<String> emptySet = new HashSet<>();
Object[] emptyArray = new Object[0];
}
ValueReferenceResolver ctx =
RefResolverHelper.createResolver(singletonMap("this", new Obj()), null);
ValueReferenceResolver ctx = RefResolverHelper.createResolver(new Obj());
assertTrue(probeCondition.execute(ctx));
}

Expand All @@ -239,8 +232,7 @@ class Obj {
Object objVal = null;
char charVal = 'a';
}
ValueReferenceResolver ctx =
RefResolverHelper.createResolver(singletonMap("this", new Obj()), null);
ValueReferenceResolver ctx = RefResolverHelper.createResolver(new Obj());
assertTrue(probeCondition.execute(ctx));
}

Expand Down Expand Up @@ -269,8 +261,7 @@ class Obj {
strList.add("foo");
}
}
ValueReferenceResolver ctx =
RefResolverHelper.createResolver(singletonMap("this", new Obj()), null);
ValueReferenceResolver ctx = RefResolverHelper.createResolver(new Obj());
assertTrue(probeCondition.execute(ctx));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,33 +8,6 @@
public class RefResolverHelper {

public static ValueReferenceResolver createResolver(Object instance) {
/*
List<Field> fields = new ArrayList<>();
Class<?> clazz = instance.getClass();
while (clazz != null) {
fields.addAll(Arrays.asList(clazz.getDeclaredFields()));
clazz = clazz.getSuperclass();
}
CapturedContext.CapturedValue[] fieldValues = new CapturedContext.CapturedValue[fields.size()];
int index = 0;
for (Field field : fields) {
try {
field.setAccessible(true);
if (Redaction.isRedactedKeyword(field.getName())) {
fieldValues[index++] =
CapturedContext.CapturedValue.redacted(
field.getName(), field.getType().getTypeName());
} else {
fieldValues[index++] =
CapturedContext.CapturedValue.of(
field.getName(), field.getType().getTypeName(), field.get(instance));
}
} catch (Exception ex) {
ex.printStackTrace();
}
}
*/
CapturedContext.CapturedValue thisValue =
CapturedContext.CapturedValue.of("this", instance.getClass().getTypeName(), instance);
return new CapturedContext(new CapturedContext.CapturedValue[] {thisValue}, null, null, null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ void testArrayHasAll() {
assertThrows(
RuntimeException.class,
() -> all(targetExpression, eq(fldRef, value(10))).evaluate(ctx));
assertEquals("Cannot dereference to field: testField", runtimeException.getMessage());
assertEquals("Cannot dereference field: testField", runtimeException.getMessage());

expression = all(targetExpression, eq(itRef, value("hello")));
assertFalse(expression.evaluate(ctx));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import static com.datadog.debugger.el.DSL.*;
import static com.datadog.debugger.el.PrettyPrintVisitor.print;
import static com.datadog.debugger.el.TestHelper.setFieldInConfig;
import static java.util.Collections.singletonMap;
import static org.junit.jupiter.api.Assertions.*;

import com.datadog.debugger.el.DSL;
Expand Down Expand Up @@ -49,13 +48,13 @@ void testPredicatedRef() {

RuntimeException runtimeException =
assertThrows(RuntimeException.class, () -> isEmptyInvalid.evaluate(ctx));
assertEquals("Cannot dereference to field: x", runtimeException.getMessage());
assertEquals("Cannot dereference field: x", runtimeException.getMessage());
runtimeException =
assertThrows(RuntimeException.class, () -> and(isEmptyInvalid, isEmpty).evaluate(ctx));
assertEquals("Cannot dereference to field: x", runtimeException.getMessage());
assertEquals("Cannot dereference field: x", runtimeException.getMessage());
runtimeException =
assertThrows(RuntimeException.class, () -> or(isEmptyInvalid, isEmpty).evaluate(ctx));
assertEquals("Cannot dereference to field: x", runtimeException.getMessage());
assertEquals("Cannot dereference field: x", runtimeException.getMessage());
assertEquals("isEmpty(x)", print(isEmptyInvalid));
}

Expand All @@ -75,8 +74,7 @@ class Obj {
exts.put(ValueReferences.DURATION_EXTENSION_NAME, duration);
exts.put(ValueReferences.EXCEPTION_EXTENSION_NAME, exception);
ValueReferenceResolver resolver =
RefResolverHelper.createResolver(singletonMap("this", new Obj()), null)
.withExtensions(exts);
RefResolverHelper.createResolver(new Obj()).withExtensions(exts);

ValueRefExpression expression = DSL.ref(ValueReferences.DURATION_REF);
assertEquals(duration, expression.evaluate(resolver).getValue());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -552,7 +552,7 @@ private InsnList collectCapturedContext(Snapshot.Kind kind, AbstractInsnNode loc
// stack: [capturedcontext]
collectStaticFields(insnList);
// stack: [capturedcontext]
collectSpecialFields(insnList);
collectCorrelationInfo(insnList);
// stack: [capturedcontext]
if (kind != Snapshot.Kind.UNHANDLED_EXCEPTION) {
/*
Expand Down Expand Up @@ -857,7 +857,7 @@ private void collectStaticFields(InsnList insnList) {
// stack: [capturedcontext]
}

private void collectSpecialFields(InsnList insnList) {
private void collectCorrelationInfo(InsnList insnList) {
// expected stack top: [capturedcontext]
/*
* We are cheating a bit with CorrelationAccess - utilizing the knowledge that it is a singleton loaded by the
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1119,8 +1119,7 @@ public void nullCondition() throws IOException, URISyntaxException {
List<EvaluationError> evaluationErrors = listener.snapshots.get(0).getEvaluationErrors();
Assertions.assertEquals(1, evaluationErrors.size());
Assertions.assertEquals("nullTyped.fld.fld", evaluationErrors.get(0).getExpr());
Assertions.assertEquals(
"Cannot dereference to field: fld", evaluationErrors.get(0).getMessage());
Assertions.assertEquals("Cannot dereference field: fld", evaluationErrors.get(0).getMessage());
}

@Test
Expand Down Expand Up @@ -1246,8 +1245,7 @@ public void mergedProbesConditionMainErrorAdditionalFalse()
List<EvaluationError> evaluationErrors = snapshots.get(0).getEvaluationErrors();
Assertions.assertEquals(1, evaluationErrors.size());
Assertions.assertEquals("nullTyped.fld.fld", evaluationErrors.get(0).getExpr());
Assertions.assertEquals(
"Cannot dereference to field: fld", evaluationErrors.get(0).getMessage());
Assertions.assertEquals("Cannot dereference field: fld", evaluationErrors.get(0).getMessage());
}

@Test
Expand All @@ -1266,8 +1264,7 @@ public void mergedProbesConditionMainErrorAdditionalTrue()
List<EvaluationError> evaluationErrors = snapshots.get(0).getEvaluationErrors();
Assertions.assertEquals(1, evaluationErrors.size());
Assertions.assertEquals("nullTyped.fld.fld", evaluationErrors.get(0).getExpr());
Assertions.assertEquals(
"Cannot dereference to field: fld", evaluationErrors.get(0).getMessage());
Assertions.assertEquals("Cannot dereference field: fld", evaluationErrors.get(0).getMessage());
assertNull(snapshots.get(1).getEvaluationErrors());
}

Expand All @@ -1287,8 +1284,7 @@ public void mergedProbesConditionMainFalseAdditionalError()
List<EvaluationError> evaluationErrors = snapshots.get(0).getEvaluationErrors();
Assertions.assertEquals(1, evaluationErrors.size());
Assertions.assertEquals("nullTyped.fld.fld", evaluationErrors.get(0).getExpr());
Assertions.assertEquals(
"Cannot dereference to field: fld", evaluationErrors.get(0).getMessage());
Assertions.assertEquals("Cannot dereference field: fld", evaluationErrors.get(0).getMessage());
}

@Test
Expand All @@ -1308,8 +1304,7 @@ public void mergedProbesConditionMainTrueAdditionalError()
List<EvaluationError> evaluationErrors = snapshots.get(1).getEvaluationErrors();
Assertions.assertEquals(1, evaluationErrors.size());
Assertions.assertEquals("nullTyped.fld.fld", evaluationErrors.get(0).getExpr());
Assertions.assertEquals(
"Cannot dereference to field: fld", evaluationErrors.get(0).getMessage());
Assertions.assertEquals("Cannot dereference field: fld", evaluationErrors.get(0).getMessage());
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -340,13 +340,11 @@ public void lineTemplateNullFieldLog() throws IOException, URISyntaxException {
Snapshot snapshot = assertOneSnapshot(listener);
assertCapturesNull(snapshot);
assertEquals(
"this is log line with field={Cannot dereference to field: intValue}",
snapshot.getMessage());
"this is log line with field={Cannot dereference field: intValue}", snapshot.getMessage());
assertEquals(1, snapshot.getEvaluationErrors().size());
assertEquals("nullObject.intValue", snapshot.getEvaluationErrors().get(0).getExpr());
assertEquals(
"Cannot dereference to field: intValue",
snapshot.getEvaluationErrors().get(0).getMessage());
"Cannot dereference field: intValue", snapshot.getEvaluationErrors().get(0).getMessage());
}

@Test
Expand Down Expand Up @@ -404,7 +402,7 @@ public void conditionWithLogTemplateEvalError() throws IOException, URISyntaxExc
Assertions.assertEquals(2, snapshot.getCaptures().getEntry().getArguments().size());
Assertions.assertEquals(1, snapshot.getEvaluationErrors().size());
Assertions.assertEquals(
"Cannot dereference to field: typoArg", snapshot.getEvaluationErrors().get(0).getMessage());
"Cannot dereference field: typoArg", snapshot.getEvaluationErrors().get(0).getMessage());
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ public void methodTagEvalError() throws IOException, URISyntaxException {
MutableSpan span = traceInterceptor.getFirstSpan();
assertNull(span.getTags().get("tag1"));
assertEquals(
"Cannot dereference to field: noarg", span.getTags().get("_dd.di.tag1.evaluation_error"));
"Cannot dereference field: noarg", span.getTags().get("_dd.di.tag1.evaluation_error"));
}

@Test
Expand All @@ -183,7 +183,7 @@ public void methodActiveSpanInvalidCondition() throws IOException, URISyntaxExce
Snapshot snapshot = mockSink.getSnapshots().get(0);
assertEquals(1, snapshot.getEvaluationErrors().size());
assertEquals(
"Cannot dereference to field: noarg", snapshot.getEvaluationErrors().get(0).getMessage());
"Cannot dereference field: noarg", snapshot.getEvaluationErrors().get(0).getMessage());
}

@Test
Expand Down Expand Up @@ -298,7 +298,7 @@ public void lineActiveSpanInvalidCondition() throws IOException, URISyntaxExcept
Snapshot snapshot = mockSink.getSnapshots().get(0);
assertEquals(1, snapshot.getEvaluationErrors().size());
assertEquals(
"Cannot dereference to field: noarg", snapshot.getEvaluationErrors().get(0).getMessage());
"Cannot dereference field: noarg", snapshot.getEvaluationErrors().get(0).getMessage());
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -193,13 +193,7 @@ public CapturedContext fromJson(JsonReader jsonReader) throws IOException {
jsonReader.beginObject();
List<CapturedContext.CapturedValue> argValues = new ArrayList<>();
while (jsonReader.hasNext()) {
String argName = jsonReader.peekJson().nextName();
// if ("this".equals(argName)) {
// jsonReader.nextName(); // consume "this"
// fromJsonFields(jsonReader, capturedContext);
// continue;
// }
argName = jsonReader.nextName();
String argName = jsonReader.nextName();
CapturedContext.CapturedValue capturedValue = valueAdapter.fromJson(jsonReader);
if (capturedValue != null) {
capturedValue.setName(argName);
Expand Down Expand Up @@ -237,11 +231,6 @@ private void fromJsonFields(JsonReader jsonReader, CapturedContext capturedConte
jsonReader.nextString();
break;
}
case FIELDS:
{
// capturedContext.addFields(fromJsonCapturedValues(jsonReader));
break;
}
case NOT_CAPTURED_REASON:
{
jsonReader.nextString();
Expand Down

0 comments on commit 32bad46

Please sign in to comment.