Skip to content

Commit 2857e3f

Browse files
authored
Improve failure reporting (#104)
In certain cases, the exception message reported by Gradle was insufficient or incorrect. This PR improves a couple of things: 1. Propagate failure received in `FinishEvent`, rather than reporting incorrectly (#103) 2. Use a contextual exception for missing input parameters, to ensure that the underlying cause is correctly reported.
2 parents 08107b1 + 745be33 commit 2857e3f

File tree

2 files changed

+12
-13
lines changed

2 files changed

+12
-13
lines changed

plugin-test/src/test/groovy/org/gradle/github/dependencygraph/DependencyExtractorConfigTest.groovy

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,6 @@ class DependencyExtractorConfigTest extends BaseExtractorTest {
9696
def result = executer.runWithFailure()
9797

9898
then:
99-
result.output.contains("'GITHUB_DEPENDENCY_GRAPH_JOB_CORRELATOR' must be set")
99+
result.output.contains("> The configuration parameter 'GITHUB_DEPENDENCY_GRAPH_JOB_CORRELATOR' must be set")
100100
}
101101
}

plugin/src/main/kotlin/org/gradle/dependencygraph/extractor/DependencyExtractor.kt

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import org.gradle.dependencygraph.model.*
1212
import org.gradle.dependencygraph.util.*
1313
import org.gradle.initialization.EvaluateSettingsBuildOperationType
1414
import org.gradle.initialization.LoadProjectsBuildOperationType
15+
import org.gradle.internal.exceptions.Contextual
1516
import org.gradle.internal.exceptions.DefaultMultiCauseException
1617
import org.gradle.internal.operations.*
1718
import java.io.File
@@ -100,14 +101,16 @@ abstract class DependencyExtractor :
100101
val details: D? = buildOperation.details.let {
101102
if (it is D) it else null
102103
}
103-
val result: R? = finishEvent.result.let {
104-
if (it is R) it else null
104+
if (details == null) {
105+
return // Ignore other build operation types
105106
}
106-
if (details == null && result == null) {
107-
return
108-
} else if (details == null || result == null) {
109-
throw IllegalStateException("buildOperation.details & finishedEvent.result were unexpected types")
107+
108+
val failure = finishEvent.failure
109+
if (failure != null) {
110+
throw failure
110111
}
112+
113+
val result: R = finishEvent.result as R
111114
handler(details, result)
112115
}
113116

@@ -311,15 +314,11 @@ abstract class DependencyExtractor :
311314
try {
312315
writeDependencyGraph()
313316
} catch (e: RuntimeException) {
314-
throw GradleException(
315-
"The dependency-graph extractor plugin encountered errors while writing the dependency snapshot json file. " +
316-
"Please report this issue at: https://github.com/gradle/github-dependency-graph-gradle-plugin/issues",
317-
e
318-
)
317+
throw DefaultMultiCauseException("Failed to write dependency-graph to file", e)
319318
}
320319
}
321320

322321
companion object {
323322
private val LOGGER = Logging.getLogger(DependencyExtractor::class.java)
324323
}
325-
}
324+
}

0 commit comments

Comments
 (0)