Skip to content

handleBuildOperationTypeRaw masks failed build operations #103

@smowton

Description

@smowton

The routine handleBuildOperationTypeRaw conflates finishedEvent.result not having the expected type with it being null.

As a result, buildOperation.details & finishedEvent.result were unexpected types is thrown if finishedEvent.failure is non-null, even though nothing was wrong with their types.

Example to reproduce:

Using repository / commit https://github.com/OpenVidu/openvidu-tutorials/tree/0f80b654742f37eed83f2881056643509f646cb6

In directory https://github.com/OpenVidu/openvidu-tutorials/tree/0f80b654742f37eed83f2881056643509f646cb6/openvidu-react-native/android

Run

./gradlew --no-daemon -Dorg.gradle.configureondemand=false -Dorg.gradle.dependency.verification=off -Dorg.gradle.warning.mode=none --init-script /tmp/dep-graph.gradle ForceDependencyResolutionPlugin_resolveAllDependencies --stacktrace -DGITHUB_DEPENDENCY_GRAPH_JOB_CORRELATOR=dep-graph -DGITHUB_DEPENDENCY_GRAPH_JOB_ID=unknown -DGITHUB_DEPENDENCY_GRAPH_SHA=unknown -DGITHUB_DEPENDENCY_GRAPH_REF=unknown -DGITHUB_DEPENDENCY_GRAPH_WORKSPACE=/tmp/openvidu-tutorials/ -DDEPENDENCY_GRAPH_REPORT_DIR=/tmp/output

Result: we get the buildOperation.details & finishedEvent.result were unexpected types message.

However if we patch the routine handleBuildOperationTypeRaw:

diff --git a/plugin/src/main/kotlin/org/gradle/dependencygraph/extractor/DependencyExtractor.kt b/plugin/src/main/kotlin/org/gradle/dependencygraph/extractor/DependencyExtractor.kt
index f47221f..2c3a8ee 100644
--- a/plugin/src/main/kotlin/org/gradle/dependencygraph/extractor/DependencyExtractor.kt
+++ b/plugin/src/main/kotlin/org/gradle/dependencygraph/extractor/DependencyExtractor.kt
@@ -103,10 +103,13 @@ abstract class DependencyExtractor :
         val result: R? = finishEvent.result.let {
             if (it is R) it else null
         }
+        val failure = finishEvent.failure
         if (details == null && result == null) {
             return
+        } else if (details != null && failure != null) {
+            throw failure
         } else if (details == null || result == null) {
-            throw IllegalStateException("buildOperation.details & finishedEvent.result were unexpected types")
+            throw IllegalStateException("buildOperation.details & finishedEvent.result were unexpected types " + buildOperation.details?.javaClass + " / " + finishEvent.result?.javaClass)
         }
         handler(details, result)
     }

Then we get the more informative error: MissingResourceException: Could not read script '/private/tmp/openvidu-tutorials/openvidu-react-native/node_modules/@react-native-community/cli-platform-android/native_modules.gradle' as it does not exist.

Gradle's exception handling here is a bit odd -- for reasons I don't fully understand, if we throw an exception without a cause, like the buildOperation.details & finishedEvent.result were unexpected types message, that seems to replace the exception provided in the FinishEvent, whereas if we throw one with finishEvent.failure as a cause it seems to be replaced by that cause. So I'm not sure exactly what the right answer looks like here, but we (a) shouldn't be complaining about types when there's nothing actually wrong with the types (actually, finishEvent.result was null because finishEvent.failure was defined instead), and (b) it would be useful to somehow expose the real underlying cause of the failure.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions