Skip to content

Commit 5e580da

Browse files
authored
Revert "Show all exceptions in the failure reports (#23)" (#33)
1 parent ecedee2 commit 5e580da

File tree

7 files changed

+26
-76
lines changed

7 files changed

+26
-76
lines changed

.gitignore

-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
*.ipr
44
*.iws
55
.idea/
6-
.profileconfig.json
76

87
# Eclipse
98
.classpath

changelog/@unreleased/pr-33.v2.yml

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
type: fix
2+
fix:
3+
description: Revert "Show all exceptions in the failure reports (#23)"
4+
links:
5+
- https://github.com/palantir/gradle-failure-reports/pull/33

gradle-failure-reports/src/main/java/com/palantir/gradle/failurereports/FailureReportsRootPlugin.java

+7-8
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import com.palantir.gradle.failurereports.util.FailureReporterResources;
2121
import com.palantir.gradle.failurereports.util.PluginResources;
2222
import java.util.List;
23+
import java.util.Optional;
2324
import one.util.streamex.StreamEx;
2425
import org.gradle.api.Plugin;
2526
import org.gradle.api.Project;
@@ -28,7 +29,6 @@
2829
import org.gradle.api.tasks.TaskContainer;
2930
import org.gradle.api.tasks.TaskProvider;
3031
import org.gradle.api.tasks.compile.JavaCompile;
31-
import org.gradle.api.tasks.testing.Test;
3232

3333
public final class FailureReportsRootPlugin implements Plugin<Project> {
3434

@@ -61,7 +61,9 @@ private void collectVerifyLocksFailureReports(Project project, TaskProvider<Fina
6161
verifyLocksTask.configure(task -> task.finalizedBy(finalizerTask));
6262

6363
finalizerTask.configure(finalizer -> finalizer.getFailureReports().addAll(project.provider(() -> {
64-
if (FailureReporterResources.executedAndFailed(verifyLocksTask.get())) {
64+
if (FailureReporterResources.executedAndFailed(verifyLocksTask.get())
65+
&& ThrowableFailureReporter.maybeGetFailureReport(verifyLocksTask.get())
66+
.isEmpty()) {
6567
return List.of(VerifyLocksFailureReporter.getFailureReport(verifyLocksTask.get()));
6668
}
6769
return List.of();
@@ -82,15 +84,12 @@ private void collectOtherTaskFailures(Project project, TaskProvider<FinalizerTas
8284
projectTasks)
8385
.filter(FailureReportsRootPlugin::isAllowedTask)
8486
.filter(FailureReporterResources::executedAndFailed)
85-
.map(ThrowableFailureReporter::getFailureReport))));
87+
.map(ThrowableFailureReporter::maybeGetFailureReport)
88+
.flatMap(Optional::stream))));
8689
});
8790
}
8891

8992
private static boolean isAllowedTask(Task task) {
90-
return !(task instanceof JavaCompile
91-
|| task instanceof Checkstyle
92-
|| task instanceof FinalizerTask
93-
|| task instanceof Test
94-
|| task.getName().equals(VERIFY_LOCKS_TASK));
93+
return !(task instanceof JavaCompile) && !(task instanceof Checkstyle) && !(task instanceof FinalizerTask);
9594
}
9695
}

gradle-failure-reports/src/main/java/com/palantir/gradle/failurereports/ThrowableFailureReporter.java

+9-18
Original file line numberDiff line numberDiff line change
@@ -22,39 +22,30 @@
2222
import com.palantir.gradle.failurereports.util.FailureReporterResources;
2323
import com.palantir.gradle.failurereports.util.ThrowableResources;
2424
import java.util.Optional;
25+
import org.gradle.api.Project;
2526
import org.gradle.api.Task;
2627

2728
public final class ThrowableFailureReporter {
2829

29-
public static <T extends Task> FailureReport getFailureReport(T task) {
30+
public static <T extends Task> Optional<FailureReport> maybeGetFailureReport(T task) {
3031
Throwable throwable = task.getState().getFailure();
31-
// retrieving the last ExceptionWithSuggestion in the causal chain
32+
// try to get the last ExtraInfoException in the causal chain
3233
Optional<ExceptionWithSuggestion> maybeExtraInfoException = Throwables.getCausalChain(throwable).stream()
3334
.filter(ExceptionWithSuggestion.class::isInstance)
3435
.map(ExceptionWithSuggestion.class::cast)
3536
.findFirst();
36-
return maybeExtraInfoException
37-
.map(exception -> getExceptionWithSuggestionReport(task, throwable, exception))
38-
.orElseGet(() -> getGenericExceptionReport(task, throwable));
37+
return maybeExtraInfoException.map(
38+
exception -> getEnhancedExceptionReport(task.getProject(), task.getPath(), throwable, exception));
3939
}
4040

4141
@SuppressWarnings("NullAway")
42-
private static <T extends Task> FailureReport getExceptionWithSuggestionReport(
43-
T task, Throwable initialThrowable, ExceptionWithSuggestion extraInfoException) {
44-
FailureReport report = task.getProject().getObjects().newInstance(FailureReport.class);
42+
public static FailureReport getEnhancedExceptionReport(
43+
Project project, String taskPath, Throwable initialThrowable, ExceptionWithSuggestion extraInfoException) {
44+
FailureReport report = project.getObjects().newInstance(FailureReport.class);
4545
report.getClickableSource().set(extraInfoException.getSuggestion());
4646
report.getErrorMessage()
4747
.set(ThrowableResources.formatThrowableWithMessage(initialThrowable, extraInfoException.getMessage()));
48-
report.getHeader()
49-
.set(FailureReporterResources.getTaskErrorHeader(task.getPath(), extraInfoException.getMessage()));
50-
return report;
51-
}
52-
53-
private static <T extends Task> FailureReport getGenericExceptionReport(T task, Throwable throwable) {
54-
FailureReport report = task.getProject().getObjects().newInstance(FailureReport.class);
55-
report.getClickableSource().set(task.getPath());
56-
report.getErrorMessage().set(ThrowableResources.formatThrowable(throwable));
57-
report.getHeader().set(FailureReporterResources.getTaskErrorHeader(task.getPath(), throwable));
48+
report.getHeader().set(FailureReporterResources.getTaskErrorHeader(taskPath, extraInfoException.getMessage()));
5849
return report;
5950
}
6051

gradle-failure-reports/src/main/java/com/palantir/gradle/failurereports/util/FailureReporterResources.java

+1-11
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616

1717
package com.palantir.gradle.failurereports.util;
1818

19-
import com.google.common.base.Throwables;
2019
import java.nio.file.Path;
2120
import java.util.Locale;
2221
import java.util.Optional;
@@ -44,7 +43,7 @@ public static String getRelativePathWithLineNumber(Path sourceDir, Path fullFile
4443
return getPathWithLineNumber(getRelativePathToProject(sourceDir, fullFilePath), lineNumber);
4544
}
4645

47-
public static String getRelativePathToProject(Path projectDir, Path fullFilePath) {
46+
private static String getRelativePathToProject(Path projectDir, Path fullFilePath) {
4847
try {
4948
return projectDir.relativize(fullFilePath).toString();
5049
} catch (IllegalArgumentException e) {
@@ -53,15 +52,6 @@ public static String getRelativePathToProject(Path projectDir, Path fullFilePath
5352
}
5453
}
5554

56-
public static String getTaskErrorHeader(String path, Throwable throwable) {
57-
Throwable rootThrowable = Throwables.getRootCause(throwable);
58-
return getTaskErrorHeader(
59-
path,
60-
Optional.ofNullable(rootThrowable.getMessage())
61-
.orElseGet(() -> String.format(
62-
"%s exception thrown", rootThrowable.getClass().getCanonicalName())));
63-
}
64-
6555
public static String getTaskErrorHeader(String taskPath, String errorDescription) {
6656
return getTaskErrorHeader(taskPath, errorDescription, ERROR_SEVERITY);
6757
}

gradle-failure-reports/src/test/groovy/com/palantir/gradle/failurereports/FailureReportsProjectsPluginIntegrationSpec.groovy

+4-10
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ class FailureReportsProjectsPluginIntegrationSpec extends IntegrationSpec {
287287
CheckedInExpectedReports.checkOrUpdateFor(projectDir, "verifyLocks")
288288
}
289289

290-
def 'All exceptions are reported as failures' () {
290+
def 'ExceptionWithSuggestion is reported as a failure' () {
291291
setup:
292292
// language=gradle
293293
buildFile << '''
@@ -320,21 +320,16 @@ class FailureReportsProjectsPluginIntegrationSpec extends IntegrationSpec {
320320
321321
tasks.register('throwGradleException') {
322322
doLast {
323-
throw new GradleException("This is a gradle exception that is not ignored")
324-
}
325-
}
326-
327-
tasks.register('throwOOM') {
328-
doLast {
329-
throw new OutOfMemoryError()
323+
throw new GradleException("This is a gradle exception that is ignored")
330324
}
331325
}
332326
'''.stripIndent(true))
333327

334328
enableTestCiRun()
335329

336330
when:
337-
ExecutionResult executionResult= runTasksWithFailure( 'throwExceptionWithSuggestedFix', 'throwInnerExceptionWithSuggestedFix', 'throwGradleException', 'throwOOM', '--continue')
331+
runTasksWithFailure( 'throwExceptionWithSuggestedFix', 'throwInnerExceptionWithSuggestedFix', 'throwGradleException', '--continue')
332+
338333

339334
then:
340335
CheckedInExpectedReports.checkOrUpdateFor(projectDir, "throwException")
@@ -399,7 +394,6 @@ class FailureReportsProjectsPluginIntegrationSpec extends IntegrationSpec {
399394
reportXml.exists()
400395
}
401396

402-
403397
def setupCompileErrorsWthGradleProperties(String gradleProperties) {
404398
buildFile << '''
405399
apply plugin: 'com.palantir.failure-reports'

gradle-failure-reports/src/test/resources/expected-throwException-error-report.xml

-28
Original file line numberDiff line numberDiff line change
@@ -30,34 +30,6 @@ Caused by: com.palantir.gradle.failurereports.exceptions.ExceptionWithSuggestion
3030
... PLACEHOLDER_NUMBER more
3131
Caused by: java.lang.RuntimeException: InnerRuntimeException
3232
... PLACEHOLDER_NUMBER more
33-
</failure>
34-
</testcase>
35-
</testsuites>
36-
<testsuites name=":myProject:throwGradleException" tests="1">
37-
<testcase name="[:myProject:throwGradleException] error: This is a gradle exception that is not ignored" className="[:myProject:throwGradleException] error: This is a gradle exception that is not ignored" time="0">
38-
<failure message="_IGNORED_IN_TESTS" type="ERROR">This is a gradle exception that is not ignored
39-
40-
* Causal chain is:
41-
org.gradle.api.tasks.TaskExecutionException: Execution failed for task ':myProject:throwGradleException'.
42-
org.gradle.api.GradleException: This is a gradle exception that is not ignored
43-
44-
* Full exception is:
45-
org.gradle.api.tasks.TaskExecutionException: Execution failed for task ':myProject:throwGradleException'.
46-
Caused by: org.gradle.api.GradleException: This is a gradle exception that is not ignored
47-
</failure>
48-
</testcase>
49-
</testsuites>
50-
<testsuites name=":myProject:throwOOM" tests="1">
51-
<testcase name="[:myProject:throwOOM] error: java.lang.OutOfMemoryError exception thrown" className="[:myProject:throwOOM] error: java.lang.OutOfMemoryError exception thrown" time="0">
52-
<failure message="_IGNORED_IN_TESTS" type="ERROR">An error occurred, java.lang.OutOfMemoryError exception thrown
53-
54-
* Causal chain is:
55-
org.gradle.api.tasks.TaskExecutionException: Execution failed for task ':myProject:throwOOM'.
56-
java.lang.OutOfMemoryError
57-
58-
* Full exception is:
59-
org.gradle.api.tasks.TaskExecutionException: Execution failed for task ':myProject:throwOOM'.
60-
Caused by: java.lang.OutOfMemoryError
6133
</failure>
6234
</testcase>
6335
</testsuites>

0 commit comments

Comments
 (0)