Skip to content

Commit

Permalink
Improve failure reporting (#104)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
bigdaz authored Jan 27, 2024
2 parents 08107b1 + 745be33 commit 2857e3f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,6 @@ class DependencyExtractorConfigTest extends BaseExtractorTest {
def result = executer.runWithFailure()

then:
result.output.contains("'GITHUB_DEPENDENCY_GRAPH_JOB_CORRELATOR' must be set")
result.output.contains("> The configuration parameter 'GITHUB_DEPENDENCY_GRAPH_JOB_CORRELATOR' must be set")
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import org.gradle.dependencygraph.model.*
import org.gradle.dependencygraph.util.*
import org.gradle.initialization.EvaluateSettingsBuildOperationType
import org.gradle.initialization.LoadProjectsBuildOperationType
import org.gradle.internal.exceptions.Contextual
import org.gradle.internal.exceptions.DefaultMultiCauseException
import org.gradle.internal.operations.*
import java.io.File
Expand Down Expand Up @@ -100,14 +101,16 @@ abstract class DependencyExtractor :
val details: D? = buildOperation.details.let {
if (it is D) it else null
}
val result: R? = finishEvent.result.let {
if (it is R) it else null
if (details == null) {
return // Ignore other build operation types
}
if (details == null && result == null) {
return
} else if (details == null || result == null) {
throw IllegalStateException("buildOperation.details & finishedEvent.result were unexpected types")

val failure = finishEvent.failure
if (failure != null) {
throw failure
}

val result: R = finishEvent.result as R
handler(details, result)
}

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

companion object {
private val LOGGER = Logging.getLogger(DependencyExtractor::class.java)
}
}
}

0 comments on commit 2857e3f

Please sign in to comment.