Skip to content

Commit 8f172ea

Browse files
Do not ignore caught exceptions in CI Visibility code (#6671)
1 parent 0c0f9cb commit 8f172ea

File tree

8 files changed

+30
-8
lines changed

8 files changed

+30
-8
lines changed

dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/git/CILocalGitInfoBuilder.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,8 @@ private Path getGitPath(String repositoryPath) {
4444
}
4545
}
4646
} catch (Exception e) {
47-
LOGGER.debug("Error while getting Git folder in " + repositoryPath, e);
47+
LOGGER.debug("Error while getting Git folder in {}", repositoryPath, e);
48+
LOGGER.warn("Error while getting Git folder");
4849
}
4950
return Paths.get(repositoryPath, gitFolderName);
5051
}

dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/git/GitClientGitInfoBuilder.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,8 @@ public GitInfo build(@Nullable String repositoryPath) {
5454
return new GitInfo(remoteUrl, branch, tag, commitInfo);
5555

5656
} catch (Exception e) {
57-
LOGGER.debug("Error while getting Git data from " + repositoryPath, e);
57+
LOGGER.debug("Error while getting Git data from {}", repositoryPath, e);
58+
LOGGER.warn("Error while getting Git data by executing shell commands");
5859
return GitInfo.NOOP;
5960
}
6061
}

dd-java-agent/instrumentation/junit-4.10/src/main/java/datadog/trace/instrumentation/junit4/JUnit4Utils.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,13 @@
1919
import org.junit.runner.notification.RunListener;
2020
import org.junit.runner.notification.RunNotifier;
2121
import org.junit.runners.ParentRunner;
22+
import org.slf4j.Logger;
23+
import org.slf4j.LoggerFactory;
2224

2325
public abstract class JUnit4Utils {
2426

27+
private static final Logger LOGGER = LoggerFactory.getLogger(JUnit4Utils.class);
28+
2529
private static final String SYNCHRONIZED_LISTENER =
2630
"org.junit.runner.notification.SynchronizedRunListener";
2731

@@ -127,6 +131,8 @@ public static Method getTestMethod(final Description description) {
127131
try {
128132
return testClass.getMethod(methodName);
129133
} catch (NoSuchMethodException e) {
134+
LOGGER.debug("Could not get method named {} in class {}", methodName, testClass, e);
135+
LOGGER.warn("Could not get test method", e);
130136
return null;
131137
}
132138
}

dd-java-agent/instrumentation/junit-5.3/spock-junit-5/src/main/java/datadog/trace/instrumentation/junit5/SpockUtils.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,16 @@
1313
import org.junit.platform.engine.TestTag;
1414
import org.junit.platform.engine.UniqueId;
1515
import org.junit.platform.engine.support.descriptor.MethodSource;
16+
import org.slf4j.Logger;
17+
import org.slf4j.LoggerFactory;
1618
import org.spockframework.runtime.SpockNode;
1719
import org.spockframework.runtime.model.FeatureMetadata;
1820
import org.spockframework.runtime.model.SpecElementInfo;
1921

2022
public class SpockUtils {
2123

24+
private static final Logger LOGGER = LoggerFactory.getLogger(SpockUtils.class);
25+
2226
private static final datadog.trace.util.MethodHandles METHOD_HANDLES =
2327
new datadog.trace.util.MethodHandles(ClassLoaderUtils.getDefaultClassLoader());
2428

@@ -50,7 +54,7 @@ public static Collection<TestTag> getTags(SpockNode<?> spockNode) {
5054
return junitPlatformTestTags;
5155

5256
} catch (Throwable throwable) {
53-
// ignore
57+
LOGGER.warn("Could not get tags from a spock node", throwable);
5458
return Collections.emptyList();
5559
}
5660
}
@@ -79,7 +83,7 @@ public static Method getTestMethod(MethodSource methodSource) {
7983
}
8084

8185
} catch (Throwable e) {
82-
// ignore
86+
LOGGER.warn("Could not get test method from method source", e);
8387
}
8488
return null;
8589
}

dd-java-agent/instrumentation/junit-5.3/src/main/java/datadog/trace/instrumentation/junit5/JUnitPlatformUtils.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
import org.junit.platform.engine.UniqueId;
1919
import org.junit.platform.engine.support.descriptor.ClassSource;
2020
import org.junit.platform.engine.support.descriptor.MethodSource;
21+
import org.slf4j.Logger;
22+
import org.slf4j.LoggerFactory;
2123

2224
/**
2325
* !!!!!!!!!!!!!!!! IMPORTANT !!!!!!!!!!!!!!!! Do not use or refer to any classes from {@code
@@ -28,6 +30,8 @@
2830
*/
2931
public abstract class JUnitPlatformUtils {
3032

33+
private static final Logger LOGGER = LoggerFactory.getLogger(JUnitPlatformUtils.class);
34+
3135
private JUnitPlatformUtils() {}
3236

3337
private static final MethodHandles METHOD_HANDLES =
@@ -72,6 +76,8 @@ public static Method getTestMethod(MethodSource methodSource) {
7276
testClass, methodName, methodSource.getMethodParameterTypes())
7377
.orElse(null);
7478
} catch (JUnitException e) {
79+
LOGGER.debug("Could not find method {} in class {}", methodName, testClass, e);
80+
LOGGER.warn("Could not find test method");
7581
return null;
7682
}
7783
}

dd-java-agent/instrumentation/maven-3.2.1/src/main/java/datadog/trace/instrumentation/maven3/MavenLifecycleParticipant.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,8 @@ private String getEffectiveJvm(Mojo mojo) {
246246
}
247247

248248
} catch (Exception e) {
249+
LOGGER.debug("Error while getting effective JVM for mojo {}", mojo, e);
250+
LOGGER.warn("Error while getting effective JVM");
249251
return null;
250252
}
251253
}

dd-java-agent/instrumentation/scalatest/src/main/java/datadog/trace/instrumentation/scalatest/ScalatestUtils.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,8 @@ public static Class<?> getClass(Option<String> className) {
4848
return CLASS_LOADER.loadClass(className.get());
4949
} catch (Exception e) {
5050
log.debug("Could not load class {}", className, e);
51+
log.warn("Could not load a Scalatest class");
5152
return null;
5253
}
5354
}
54-
55-
public static void test(Object invokeWithFixture) {
56-
System.out.println("tdest"); // FIXME remove - scala.Function1
57-
}
5855
}

dd-java-agent/instrumentation/testng/src/main/java/datadog/trace/instrumentation/testng/TestNGUtils.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
import java.util.Collections;
1212
import java.util.List;
1313
import java.util.Properties;
14+
import org.slf4j.Logger;
15+
import org.slf4j.LoggerFactory;
1416
import org.testng.IClass;
1517
import org.testng.ITestClass;
1618
import org.testng.ITestContext;
@@ -25,6 +27,8 @@
2527

2628
public abstract class TestNGUtils {
2729

30+
private static final Logger LOGGER = LoggerFactory.getLogger(TestNGUtils.class);
31+
2832
private static final datadog.trace.util.MethodHandles METHOD_HANDLES =
2933
new datadog.trace.util.MethodHandles(TestNG.class.getClassLoader());
3034

@@ -161,6 +165,7 @@ public static boolean isParallelized(ITestClass testClass) {
161165
return parallel != null
162166
&& ("methods".equals(parallel.toString()) || "tests".equals(parallel.toString()));
163167
} catch (Throwable e) {
168+
LOGGER.warn("Error while checking if a test class is paralellized");
164169
return false;
165170
}
166171
}

0 commit comments

Comments
 (0)