Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve failure reporting #104

Merged
merged 3 commits into from
Jan 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm curious what causes these types to not align such that one is null but not the other.

I definitely think this is the right fix, but I'm confused why this exception was being thrown

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See #103 for more background

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)
}
}
}
Loading